From 614d0c6f1b2015cf213a1f95322fba587f582160 Mon Sep 17 00:00:00 2001 From: 3Shain Date: Wed, 8 Mar 2023 00:57:07 +0000 Subject: [PATCH] feat: detect multiple instances --- src/app.tsx | 12 ++++++++++++ src/utils/neu.ts | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app.tsx b/src/app.tsx index a4012ff..f3e321e 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -9,6 +9,9 @@ import { prompt, addTerminationHook, GLOBAL_onClose, + getKey, + setKey, + alert, } from "./utils"; import { createAria2 } from "./aria2"; import { checkWine, createWine, createWineInstallProgram } from "./wine"; @@ -20,6 +23,15 @@ import { createUpdater, downloadProgram } from "./updater"; import { createCommonUpdateUI } from "./common-update-ui"; export async function createApp() { + try { + await getKey("singleton"); + await alert("NOTE", "LAUNCHER_ALREADY_EXISTS"); + Neutralino.app.exit(0); + return () => null; + } catch { + await setKey("singleton", "1"); + } + let aria2_port = 6868; await Neutralino.events.on("ready", async () => {}); diff --git a/src/utils/neu.ts b/src/utils/neu.ts index 40ef893..ca4ead5 100644 --- a/src/utils/neu.ts +++ b/src/utils/neu.ts @@ -152,7 +152,10 @@ export async function stats(path: string) { return await Neutralino.filesystem.getStats(path); } -const hooks: Array<(forced: boolean) => Promise> = []; +const hooks: Array<(forced: boolean) => Promise> = [async ()=>{ + await setKey("singleton", null); + return true; +}]; export function addTerminationHook(fn: (forced: boolean) => Promise) { hooks.push(fn);