diff --git a/src/pages/index.ts b/src/pages/index.ts index 98d1b3d..a620c40 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -4,6 +4,7 @@ import constants from '../ts/Constants'; import Archive from '../ts/core/Archive'; import Debug from '../ts/core/Debug'; import Downloader from '../ts/core/Downloader'; +import IPC from '../ts/core/IPC'; declare const Neutralino; @@ -18,6 +19,8 @@ Neutralino.events.on('windowClose', () => { constants.paths.launcherDir.then(async (path) => { const time = new Date; + await IPC.purge(); + Neutralino.filesystem.getStats(`${path}/logs`) .then(() => saveLog()) .catch(async () => { diff --git a/src/splash.svelte b/src/splash.svelte index 184e44f..a5bd57f 100644 --- a/src/splash.svelte +++ b/src/splash.svelte @@ -23,12 +23,13 @@ }); const isLauncherLoaded = () => { - IPC.read().then((records) => { + IPC.read().then(async (records) => { const launcherLoaded = records.filter((record) => record.data === 'launcher-loaded'); if (launcherLoaded.length > 0) { - launcherLoaded.forEach((record) => record.pop()); + for (const record of launcherLoaded) + await record.pop(); Window.current.hide(); diff --git a/src/ts/core/IPC.ts b/src/ts/core/IPC.ts index 795ad8c..3173824 100644 --- a/src/ts/core/IPC.ts +++ b/src/ts/core/IPC.ts @@ -24,6 +24,15 @@ class IPCRecord return this; } + + public get(): { id: number; time: number; data: any} + { + return { + id: this.id, + time: this.time, + data: this.data + }; + } } export default class IPC @@ -35,7 +44,7 @@ export default class IPC { return new Promise(async (resolve) => { Neutralino.filesystem.readFile(`${await constants.paths.launcherDir}/.ipc.json`) - .then((data) => resolve(JSON.parse(data))) + .then((data) => resolve(JSON.parse(data).map((record) => new IPCRecord(record.id, record.time, record.data)))) .catch(() => resolve([])); }); } @@ -68,13 +77,25 @@ export default class IPC return new Promise(async (resolve) => { let records = await this.read(); - records = records.filter((item) => item.id !== record.id && item.time !== record.time); + records = records.filter((item) => item.id !== record.id || item.time !== record.time); await Neutralino.filesystem.writeFile(`${await constants.paths.launcherDir}/.ipc.json`, JSON.stringify(records)); resolve(); }); } + + /** + * Remove all the record from the "shared inter-process storage" + */ + public static purge(): Promise + { + return new Promise(async (resolve) => { + Neutralino.filesystem.removeFile(`${await constants.paths.launcherDir}/.ipc.json`) + .then(() => resolve()) + .catch(() => resolve()); + }); + } }; export { IPCRecord };