feat(desktop): use unique appdata if port is different

This commit is contained in:
Elian Doran 2025-09-16 18:42:37 +03:00
parent 0fcff6639f
commit a840d91379
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View File

@ -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",

View File

@ -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<void>();
// 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');