mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-21 01:11:46 +03:00
Improved IPC class working
This commit is contained in:
parent
e87f3526c0
commit
4a2250277d
3 changed files with 29 additions and 4 deletions
|
@ -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 () => {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<void>
|
||||
{
|
||||
return new Promise(async (resolve) => {
|
||||
Neutralino.filesystem.removeFile(`${await constants.paths.launcherDir}/.ipc.json`)
|
||||
.then(() => resolve())
|
||||
.catch(() => resolve());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export { IPCRecord };
|
||||
|
|
Loading…
Reference in a new issue