From cef808641946d13a9874e5785a93afdbd151128c Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Tue, 3 Sep 2024 08:23:05 +0000 Subject: [PATCH] The new instance makes the dialog box error not display --- .vscode/settings.json | 3 +++ src/www.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6322c31c1..a2203a03b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,4 +14,7 @@ "[javascript]": { "editor.defaultFormatter": "vscode.typescript-language-features" }, + "[typescript]": { + "editor.defaultFormatter": "vscode.typescript-language-features" + }, } diff --git a/src/www.ts b/src/www.ts index 6f9613aff..27f445615 100644 --- a/src/www.ts +++ b/src/www.ts @@ -144,7 +144,17 @@ function startHttpServer() { } if (utils.isElectron()) { - import("electron").then(({ dialog }) => { + import("electron").then(({ app, dialog }) => { + // Not all situations require showing an error dialog. When Trilium is already open, + // clicking the shortcut, the software icon, or the taskbar icon, or when creating a new window, + // should simply focus on the existing window or open a new one, without displaying an error message. + if ("code" in error && error.code == 'EADDRINUSE') { + const isNewWindow = process.argv.includes('--new-window'); + if (isNewWindow || !app.requestSingleInstanceLock()) { + console.error(message); + process.exit(1); + } + } dialog.showErrorBox("Error while initializing the server", message); process.exit(1); });