Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions apps/server/src/www.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ function startHttpServer(app: Express) {
// 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") {
if (process.argv.includes("--new-window") || !app.requestSingleInstanceLock()) {
console.error(message);
process.exit(1);
}
if ("code" in error && error.code === "EADDRINUSE" && (process.argv.includes("--new-window") || !app.requestSingleInstanceLock())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition for this if statement is quite long and combines multiple checks. To improve readability and make the code more self-documenting, you could extract this logic into a helper function. For example, a function named isSecondInstanceLaunch would make the intent of this conditional block immediately clear.

console.error(message);
process.exit(1);
} else {
dialog.showErrorBox("Error while initializing the server", message);
process.exit(1);
}
dialog.showErrorBox("Error while initializing the server", message);
process.exit(1);
});
} else {
console.error(message);
Expand Down