diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 3617c4c9f4..6a3ca896ce 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -101,9 +101,22 @@ async function main() {
/**
* 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.
+ *
+ * When running in portable mode (TRILIUM_DATA_DIR is set), the user data is stored inside the data directory
+ * so that no files are written to the system's roaming profile (e.g. %APPDATA% on Windows).
+ * This can be overridden by setting TRILIUM_ELECTRON_DATA_DIR to a custom path.
*/
function getUserData() {
+ if (process.env.TRILIUM_ELECTRON_DATA_DIR) {
+ return process.env.TRILIUM_ELECTRON_DATA_DIR;
+ }
+
const name = `${app.getName()}-${port}`;
+
+ if (process.env.TRILIUM_DATA_DIR) {
+ return join(process.env.TRILIUM_DATA_DIR, "electron-user-data", name);
+ }
+
return join(app.getPath("appData"), name);
}
diff --git a/docs/User Guide/User Guide/Installation & Setup/Data directory.md b/docs/User Guide/User Guide/Installation & Setup/Data directory.md
index 3d66bafe90..3a447f82f2 100644
--- a/docs/User Guide/User Guide/Installation & Setup/Data directory.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Data directory.md
@@ -77,6 +77,14 @@ TRILIUM_DATA_DIR=/home/myuser/data/my-trilium-data trilium
You can then save the above command as a shell script on your path for convenience.
+## Electron user data directory (desktop only)
+
+When running the desktop application, Electron stores internal data (caches, spell-check dictionaries, session storage, etc.) separately from the Trilium data directory. By default this goes to the system's application data folder (e.g. `%APPDATA%` on Windows), which may be undesirable in corporate environments with roaming profiles or when running in portable mode.
+
+When `TRILIUM_DATA_DIR` is set (e.g. via the `trilium-portable` script), the Electron user data is automatically redirected into `${TRILIUM_DATA_DIR}/electron-user-data/`, so no files are written to the system's roaming profile.
+
+If you need to store the Electron data in a different location than the Trilium data directory, you can set the `TRILIUM_ELECTRON_DATA_DIR` environment variable to an explicit path.
+
## Fine-grained directory/path location
Apart from the data directory, some of the subdirectories of it can be moved elsewhere by changing an environment variable:
@@ -88,4 +96,5 @@ Apart from the data directory, some of the subdirectories of it can be moved els
| `TRILIUM_LOG_DIR` | `${TRILIUM_DATA_DIR}/log` | Directory where daily Backend (server) logs are stored. |
| `TRILIUM_TMP_DIR` | `${TRILIUM_DATA_DIR}/tmp` | Directory where temporary files are stored (for example when opening in an external app). |
| `TRILIUM_ANONYMIZED_DB_DIR` | `${TRILIUM_DATA_DIR}/anonymized-db` | Directory where a Anonymized Database is stored. |
-| `TRILIUM_CONFIG_INI_PATH` | `${TRILIUM_DATA_DIR}/config.ini` | Path to Configuration (config.ini or environment variables) file. |
\ No newline at end of file
+| `TRILIUM_CONFIG_INI_PATH` | `${TRILIUM_DATA_DIR}/config.ini` | Path to Configuration (config.ini or environment variables) file. |
+| `TRILIUM_ELECTRON_DATA_DIR` | `${TRILIUM_DATA_DIR}/electron-user-data` (portable) or system appData (default) | Directory where Electron stores internal data such as caches and spell-check dictionaries (desktop only). |
diff --git a/docs/User Guide/User Guide/Installation & Setup/Desktop Installation.md b/docs/User Guide/User Guide/Installation & Setup/Desktop Installation.md
index c8eb58ee57..b39241c459 100644
--- a/docs/User Guide/User Guide/Installation & Setup/Desktop Installation.md
+++ b/docs/User Guide/User Guide/Installation & Setup/Desktop Installation.md
@@ -11,7 +11,7 @@ Trilium offers various startup scripts to customize your experience:
* `trilium-no-cert-check`: Starts Trilium without validating [TLS certificates](Server%20Installation/HTTPS%20\(TLS\).md), useful if connecting to a server with a self-signed certificate.
* Alternatively, set the `NODE_TLS_REJECT_UNAUTHORIZED=0` environment variable before starting Trilium.
-* `trilium-portable`: Launches Trilium in portable mode, where the [data directory](Data%20directory.md) is created within the application's directory, making it easy to move the entire setup.
+* `trilium-portable`: Launches Trilium in portable mode, where the [data directory](Data%20directory.md) is created within the application's directory, making it easy to move the entire setup. Electron's internal data (caches, dictionaries, etc.) is also stored within the data directory, so no files are written to the system's roaming profile.
* `trilium-safe-mode`: Boots Trilium in "safe mode," disabling any startup scripts that might cause the application to crash.
## Synchronization