diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 46dd67af5..bfa578186 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/TriliumNext/Notes" }, "scripts": { - "dev": "cross-env TRILIUM_PORT=37741 TRILIUM_DATA_DIR=data tsx ../../scripts/electron-start.mts src/main.ts", + "dev": "cross-env TRILIUM_PORT=37742 TRILIUM_DATA_DIR=data tsx ../../scripts/electron-start.mts src/main.ts", "start-no-dir": "cross-env TRILIUM_PORT=37743 tsx ../../scripts/electron-start.mts src/main.ts", "build": "tsx scripts/build.ts", "start-prod": "pnpm build && cross-env TRILIUM_DATA_DIR=data TRILIUM_PORT=37841 ELECTRON_IS_DEV=0 electron dist", diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 42156a499..000d4c458 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -10,8 +10,13 @@ import electronDebug from "electron-debug"; import electronDl from "electron-dl"; import { deferred } from "@triliumnext/server/src/services/utils.js"; import { PRODUCT_NAME } from "./app-info"; +import port from "@triliumnext/server/src/services/port.js"; +import { join } from "path"; async function main() { + const userDataPath = getUserData(); + app.setPath("userData", userDataPath); + const serverInitializedPromise = deferred(); // Prevent Trilium starting twice on first install and on uninstall for the Windows installer. @@ -89,6 +94,14 @@ async function main() { serverInitializedPromise.resolve(); } +/** + * Returns a unique user data directory for Electron so that single instance locks between legitimately different instances such as different port or data directory can still act independently, but we are focusing the main window otherwise. + */ +function getUserData() { + const name = `${app.getName()}-${port}`; + return join(app.getPath("appData"), name); +} + async function onReady() { // app.setAppUserModelId('com.github.zadam.trilium');