From d074a5a445b73ca195a49814a935300f9e895aaa Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 6 Aug 2024 14:28:03 +0700 Subject: [PATCH] fix: should not let second instance terminate cortex (#3274) --- electron/main.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 02e174eab..455e837f8 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -64,6 +64,27 @@ const host = '127.0.0.1' app .whenReady() + .then(() => { + if (!gotTheLock) { + app.quit() + throw new Error('Another instance of the app is already running') + } else { + app.on( + 'second-instance', + (_event, commandLine, _workingDirectory): void => { + if (process.platform === 'win32' || process.platform === 'linux') { + // this is for handling deeplink on windows and linux + // since those OS will emit second-instance instead of open-url + const url = commandLine.pop() + if (url) { + windowManager.sendMainAppDeepLink(url) + } + } + windowManager.showMainWindow() + } + ) + } + }) .then(() => killProcessesOnPort(cortexCppPort)) .then(() => killProcessesOnPort(cortexJsPort)) .then(() => { @@ -98,27 +119,6 @@ app log.info(`stdout: ${stdout}`) }) }) - .then(() => { - if (!gotTheLock) { - app.quit() - throw new Error('Another instance of the app is already running') - } else { - app.on( - 'second-instance', - (_event, commandLine, _workingDirectory): void => { - if (process.platform === 'win32' || process.platform === 'linux') { - // this is for handling deeplink on windows and linux - // since those OS will emit second-instance instead of open-url - const url = commandLine.pop() - if (url) { - windowManager.sendMainAppDeepLink(url) - } - } - windowManager.showMainWindow() - } - ) - } - }) .then(setupCore) .then(createUserSpace) .then(migrate)