mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2025-03-11 02:29:37 +03:00
Added log files auto-saving
This commit is contained in:
parent
b643823d60
commit
6983ca6c36
2 changed files with 41 additions and 18 deletions
|
@ -23,8 +23,13 @@
|
|||
import Download from './assets/images/cloud-download.png';
|
||||
|
||||
constants.paths.launcherDir.then((dir) => {
|
||||
// Create launcher folder if it doesn't exist
|
||||
Neutralino.filesystem.getStats(dir)
|
||||
.catch(() => Neutralino.filesystem.createDirectory(dir));
|
||||
|
||||
// Create logs folder if it doesn't exist
|
||||
Neutralino.filesystem.getStats(`${dir}/logs`)
|
||||
.catch(() => Neutralino.filesystem.createDirectory(`${dir}/logs`));
|
||||
});
|
||||
|
||||
const launcher = new Launcher(onMount);
|
||||
|
@ -44,8 +49,6 @@
|
|||
Archive.closeStreams(true);
|
||||
|
||||
constants.paths.launcherDir.then(async (path) => {
|
||||
const time = new Date;
|
||||
|
||||
// Remove IPC file
|
||||
await IPC.purge();
|
||||
|
||||
|
@ -56,26 +59,34 @@
|
|||
// Remove .tmp files from the launcher folder
|
||||
await Neutralino.os.execCommand(`rm -f "${Process.addSlashes(`${path}/*.tmp`)}"`);
|
||||
|
||||
// Create logs folder if it doesn't exist
|
||||
Neutralino.filesystem.getStats(`${path}/logs`)
|
||||
.then(() => saveLog())
|
||||
.catch(async () => {
|
||||
await Neutralino.filesystem.createDirectory(`${path}/logs`);
|
||||
|
||||
saveLog();
|
||||
});
|
||||
|
||||
// Save logs
|
||||
const saveLog = async () => {
|
||||
const log = Debug.get().join("\r\n");
|
||||
const log = Debug.get().join("\r\n");
|
||||
|
||||
if (log != '')
|
||||
await Neutralino.filesystem.writeFile(`${await constants.paths.launcherDir}/logs/${Debug.startedAt.getDate()}-${Debug.startedAt.getMonth() + 1}-${Debug.startedAt.getFullYear()}-${Debug.startedAt.getHours()}-${Debug.startedAt.getMinutes()}-${Debug.startedAt.getSeconds()}.log`, log);
|
||||
|
||||
// And close the launcher when they was saved
|
||||
Neutralino.app.exit();
|
||||
});
|
||||
});
|
||||
|
||||
// Save logs
|
||||
let logSavingStarted = false;
|
||||
|
||||
Debug.handler(() => {
|
||||
if (!logSavingStarted)
|
||||
{
|
||||
logSavingStarted = true;
|
||||
|
||||
setTimeout(async () => {
|
||||
const log = `=== Log can be incomplete ===\r\n\r\n${Debug.get().join("\r\n")}`;
|
||||
|
||||
if (log != '')
|
||||
await Neutralino.filesystem.writeFile(`${path}/logs/${time.getDate()}-${time.getMonth() + 1}-${time.getFullYear()}-${time.getHours()}-${time.getMinutes()}-${time.getSeconds()}.log`, log);
|
||||
await Neutralino.filesystem.writeFile(`${await constants.paths.launcherDir}/logs/${Debug.startedAt.getDate()}-${Debug.startedAt.getMonth() + 1}-${Debug.startedAt.getFullYear()}-${Debug.startedAt.getHours()}-${Debug.startedAt.getMinutes()}-${Debug.startedAt.getSeconds()}.log`, log);
|
||||
|
||||
// And close the launcher when they was saved
|
||||
Neutralino.app.exit();
|
||||
};
|
||||
});
|
||||
logSavingStarted = false;
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
// Do some stuff when all the content will be loaded
|
||||
|
|
|
@ -29,7 +29,11 @@ class DebugThread
|
|||
|
||||
class Debug
|
||||
{
|
||||
public static readonly startedAt = new Date;
|
||||
|
||||
protected static logOutput: LogRecord[] = [];
|
||||
|
||||
protected static onLogHandler?: (record: LogRecord) => void;
|
||||
|
||||
protected static formatTime(time: number): string
|
||||
{
|
||||
|
@ -86,6 +90,9 @@ class Debug
|
|||
console.log(output.log.join('\r\n'));
|
||||
|
||||
this.logOutput.push(output);
|
||||
|
||||
if (this.onLogHandler)
|
||||
this.onLogHandler(output);
|
||||
}
|
||||
|
||||
public static merge(records: LogRecord[])
|
||||
|
@ -109,6 +116,11 @@ class Debug
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
public static handler(handler: (record: LogRecord) => void)
|
||||
{
|
||||
this.onLogHandler = handler;
|
||||
}
|
||||
}
|
||||
|
||||
export default Debug;
|
||||
|
|
Loading…
Add table
Reference in a new issue