mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Merge branch 'master' into build/rpm
This commit is contained in:
@@ -138,5 +138,9 @@
|
||||
{
|
||||
"username": "Alexander Herman",
|
||||
"type": "gold"
|
||||
},
|
||||
{
|
||||
"username": "Arts Rimuro Suraimu",
|
||||
"type": "gold"
|
||||
}
|
||||
]
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@
|
||||
"url": "https://github.com/Zagrios"
|
||||
},
|
||||
"contributors": [],
|
||||
"license": "MIT",
|
||||
"license": "GPL-3.0-only",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Zagrios/bs-manager/issues"
|
||||
},
|
||||
|
||||
+57
-60
@@ -23,7 +23,7 @@ import { LivShortcut } from "./services/liv/liv-shortcut.service";
|
||||
import { SteamLauncherService } from "./services/bs-launcher/steam-launcher.service";
|
||||
import { FileAssociationService } from "./services/file-association.service";
|
||||
import { SongDetailsCacheService } from "./services/additional-content/maps/song-details-cache.service";
|
||||
import { readdirSync, statSync, unlinkSync } from "fs-extra";
|
||||
import { Dirent, readdirSync, rmSync, unlinkSync } from "fs-extra";
|
||||
import { StaticConfigurationService } from "./services/static-configuration.service";
|
||||
import { configureProxy } from './helpers/proxy.helpers';
|
||||
|
||||
@@ -37,7 +37,7 @@ export const filterPatterns = new Set<RegExp>();
|
||||
filterPatterns.add(/(FRL|OC)\S{10,}/g);
|
||||
|
||||
initLogger();
|
||||
deleteOlestLogs();
|
||||
deleteOldestLogs();
|
||||
deleteOldLogs();
|
||||
|
||||
staticConfig.take("disable-hadware-acceleration", disabled => {
|
||||
@@ -156,11 +156,30 @@ if (!gotTheLock) {
|
||||
}).catch(log.error);
|
||||
}
|
||||
|
||||
function convertDateToDateString(date: Date): string {
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||
const day = date.getDate().toString().padStart(2, "0");
|
||||
return `${date.getFullYear()}-${month}-${day}`;
|
||||
}
|
||||
|
||||
function initLogger(){
|
||||
log.transports.file.level = "info";
|
||||
|
||||
let filepath = "";
|
||||
let currentDateString = convertDateToDateString(new Date());
|
||||
log.transports.file.resolvePath = () => {
|
||||
const now = new Date();
|
||||
return path.join(app.getPath("logs"), `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}-v${app.getVersion()}.log`);
|
||||
const nowString = convertDateToDateString(now);
|
||||
if (filepath && nowString === currentDateString) {
|
||||
return filepath;
|
||||
}
|
||||
|
||||
filepath = path.join(
|
||||
app.getPath("logs"), nowString,
|
||||
`${now.getTime()}-v${app.getVersion()}.log`
|
||||
);
|
||||
currentDateString = nowString;
|
||||
return filepath;
|
||||
};
|
||||
|
||||
log.hooks.push((message) => {
|
||||
@@ -203,68 +222,46 @@ function initLogger(){
|
||||
log.catchErrors();
|
||||
}
|
||||
|
||||
function getLogFilesEntries() {
|
||||
// Keep only the past week (7 days) of logs
|
||||
function deleteOldLogs(): void {
|
||||
let deleteLogFolders: Dirent[] = [];
|
||||
try {
|
||||
const logsFolder = app.getPath("logs");
|
||||
let logs = readdirSync(logsFolder, { withFileTypes: true });
|
||||
|
||||
logs = logs.filter(file => file.isFile() && path.extname(file.name) === ".log");
|
||||
|
||||
logs.sort((a, b) => {
|
||||
const aStat = statSync(path.join(logsFolder, a.name));
|
||||
const bStat = statSync(path.join(logsFolder, b.name));
|
||||
return bStat.mtime.getTime() - aStat.mtime.getTime();
|
||||
});
|
||||
|
||||
return logs.map(file => {
|
||||
const filePath = path.join(logsFolder, file.name);
|
||||
const stat = statSync(filePath);
|
||||
return {
|
||||
path: filePath,
|
||||
name: file.name,
|
||||
stats: stat
|
||||
};
|
||||
});
|
||||
} catch (err) {
|
||||
log.error('Error while retrieving log files entries:', err);
|
||||
return [];
|
||||
const filterDate = convertDateToDateString(
|
||||
new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // 7 days
|
||||
);
|
||||
deleteLogFolders = readdirSync(app.getPath("logs"), { withFileTypes: true })
|
||||
.filter(folder => folder.isDirectory() && folder.name <= filterDate);
|
||||
} catch (error) {
|
||||
log.error("Error while deleting old logs:", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// keep only the last 5 logs
|
||||
function deleteOldLogs(): void{
|
||||
try {
|
||||
let logs = getLogFilesEntries();
|
||||
|
||||
logs = logs.slice(5);
|
||||
|
||||
logs.forEach(file => {
|
||||
try {
|
||||
unlinkSync(file.path);
|
||||
log.info(`Deleted log file: ${file.path}`);
|
||||
} catch (err) {
|
||||
log.error(`Error deleting file ${file.path}:`, err);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
log.error("Error while deleting old logs:", err);
|
||||
}
|
||||
}
|
||||
|
||||
// Temporary function to delete logs before 2024-07-31
|
||||
function deleteOlestLogs(): void{
|
||||
// delete all logs before 2024-07-31
|
||||
const date = new Date(2024, 6, 31); // month is 0-based
|
||||
const logs = getLogFilesEntries().filter(file => file.stats.mtime.getTime() < date.getTime());
|
||||
|
||||
logs.forEach(file => {
|
||||
for (const folder of deleteLogFolders) {
|
||||
const folderPath = path.join(folder.parentPath, folder.name);
|
||||
try {
|
||||
unlinkSync(file.path);
|
||||
log.info(`Deleted log file: ${file.path}`);
|
||||
} catch (err) {
|
||||
log.error(`Error deleting file ${file.path}:`, err);
|
||||
rmSync(folderPath, { recursive: true, force: true });
|
||||
log.info("Deleted log folder:", folderPath);
|
||||
} catch (error) {
|
||||
log.error("Error deleting folder:", folderPath, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Obsolete behavior, delete log files that are on the parent log folder
|
||||
function deleteOldestLogs(): void {
|
||||
const logsFolder = app.getPath("logs");
|
||||
const logs = readdirSync(logsFolder, { withFileTypes: true })
|
||||
.filter(file => file.isFile() && path.extname(file.name) === ".log");
|
||||
|
||||
for (const file of logs) {
|
||||
const filepath = path.join(file.parentPath, file.name);
|
||||
try {
|
||||
unlinkSync(filepath);
|
||||
log.info("Deleted log file:", filepath);
|
||||
} catch (error) {
|
||||
log.error("Error deleting file:", filepath, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function addFilterStringLog(filter: string): void {
|
||||
|
||||
+6
-4
@@ -8,6 +8,7 @@ import { IpcService } from "renderer/services/ipc.service";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
import { logRenderError } from "renderer";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
import { DEFAULT_PLAYLIST_COVER } from "shared/models/playlists/local-playlist.models";
|
||||
|
||||
type OutProps = {
|
||||
playlistTitle: string;
|
||||
@@ -34,7 +35,9 @@ export const EditPlaylistInfosModal: ModalComponent<OutProps, Props> = ({ resolv
|
||||
const [title, setTitle] = useState(playlistTitle);
|
||||
const [description, setDescription] = useState(playlistDescription);
|
||||
const [author, setAuthor] = useState(playlistAuthor ?? steamDownloader.getSteamUsername());
|
||||
const [base64, setBase64] = useState(base64Image);
|
||||
|
||||
// Playlist cover or Default playlist cover
|
||||
const [base64, setBase64] = useState(base64Image || DEFAULT_PLAYLIST_COVER);
|
||||
|
||||
const handleClickImage = async () => {
|
||||
const res = await lastValueFrom(ipc.sendV2("choose-image", { base64: true })).catch(logRenderError) as string[];
|
||||
@@ -60,12 +63,11 @@ export const EditPlaylistInfosModal: ModalComponent<OutProps, Props> = ({ resolv
|
||||
</h1>
|
||||
<div className="w-full flex flex-col justify-center items-center">
|
||||
<button className="flex justify-center items-center relative size-36 border-2 border-gray-400 bg-theme-1 rounded-md overflow-hidden" onClick={handleClickImage}>
|
||||
{base64 ? (
|
||||
{base64 && (
|
||||
<BsmImage className="absolute size-full cursor-pointer" base64={base64} />
|
||||
) : (
|
||||
<span className="absolute size-full flex justify-center items-center p-2">{t("playlist.choose-image")}</span>
|
||||
)}
|
||||
</button>
|
||||
<span className="size-full flex justify-center items-center mb-1">{t("playlist.choose-image")}</span>
|
||||
<div className="w-full">
|
||||
<label className="font-bold cursor-pointer tracking-wide" htmlFor="playlist-title">{t("playlist.title")}</label>
|
||||
<input id="playlist-title" type="text" className="w-full bg-theme-1 px-1 py-0.5 rounded-md outline-none h-9" value={title} placeholder={t("playlist.playlist-title")} onChange={e => setTitle(e.target.value)}/>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user