From 5603b4e2f8c6ce7ad188a4906b3869cd397c13d0 Mon Sep 17 00:00:00 2001 From: Mehmet Bektas Date: Sun, 17 Mar 2024 18:56:27 -0700 Subject: [PATCH 1/2] set Snap home and userData directories --- src/main/main.ts | 7 +++++++ src/main/utils.ts | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/main/main.ts b/src/main/main.ts index 114a9cb2..a4cffb78 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,12 +9,19 @@ import { getBundledPythonPath, installBundledEnvironment, isDevMode, + isSnap, jlabCLICommandIsSetup, setupJlabCommandWithUserRights, versionWithoutSuffix, waitForDuration, waitForFunction } from './utils'; + +if (isSnap()) { + app.setPath('home', process.env.HOME); + app.setPath('userData', `${process.env.HOME}/.config/${app.getName()}`); +} + import { JupyterApplication } from './app'; import { ICLIArguments } from './tokens'; import { SessionConfig } from './config/sessionconfig'; diff --git a/src/main/utils.ts b/src/main/utils.ts index 1692d62e..bd44e909 100644 --- a/src/main/utils.ts +++ b/src/main/utils.ts @@ -30,6 +30,10 @@ export function isDevMode(): boolean { return require.main.filename.indexOf('app.asar') === -1; } +export function isSnap(): boolean { + return process.platform === 'linux' && process.env.SNAP !== undefined; +} + export function getAppDir(): string { let appDir = app.getAppPath(); if (!isDevMode()) { From c09b8f6b4d5074b364edc4d9f71a2a65dd5c6348 Mon Sep 17 00:00:00 2001 From: Mehmet Bektas Date: Fri, 22 Mar 2024 17:24:44 -0700 Subject: [PATCH 2/2] update additional paths --- src/main/main.ts | 39 ++++++++++++++++++++++++++++++++------- src/main/utils.ts | 4 ---- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index a4cffb78..15e4591e 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -1,5 +1,9 @@ import { app, Menu, MenuItem } from 'electron'; -import log, { LevelOption } from 'electron-log'; + +// Update paths to prevent Snap saving persistent data to version specific paths. +// (Must be called before any other initialization) +updatePathsForSnap(); + import * as fs from 'fs'; import * as semver from 'semver'; import { @@ -9,7 +13,6 @@ import { getBundledPythonPath, installBundledEnvironment, isDevMode, - isSnap, jlabCLICommandIsSetup, setupJlabCommandWithUserRights, versionWithoutSuffix, @@ -17,11 +20,7 @@ import { waitForFunction } from './utils'; -if (isSnap()) { - app.setPath('home', process.env.HOME); - app.setPath('userData', `${process.env.HOME}/.config/${app.getName()}`); -} - +import log, { LevelOption } from 'electron-log'; import { JupyterApplication } from './app'; import { ICLIArguments } from './tokens'; import { SessionConfig } from './config/sessionconfig'; @@ -52,6 +51,32 @@ async function appReady(): Promise { */ require('fix-path')(); +/** + * Update app home, appData, userData and logs paths to prevent + * Snap to save Python environments and logs in version specific locations + */ +function updatePathsForSnap() { + const isSnap = (): boolean => { + return process.platform === 'linux' && process.env.SNAP !== undefined; + }; + + if (!isSnap()) { + return; + } + + const userHome = process.env.HOME; + process.env.XDG_CONFIG_HOME = `${userHome}/.config`; + // Jupyter uses this path (.local/share) + process.env.XDG_DATA_HOME = `${userHome}/.local/share`; + const appDataDir = process.env.XDG_CONFIG_HOME; + const userDataDir = `${appDataDir}/${app.getName()}`; + + app.setPath('home', userHome); + app.setPath('appData', appDataDir); + app.setPath('userData', userDataDir); + app.setAppLogsPath(`${userDataDir}/logs`); +} + function getLogLevel(): LevelOption { if (isDevMode()) { return 'debug'; diff --git a/src/main/utils.ts b/src/main/utils.ts index bd44e909..1692d62e 100644 --- a/src/main/utils.ts +++ b/src/main/utils.ts @@ -30,10 +30,6 @@ export function isDevMode(): boolean { return require.main.filename.indexOf('app.asar') === -1; } -export function isSnap(): boolean { - return process.platform === 'linux' && process.env.SNAP !== undefined; -} - export function getAppDir(): string { let appDir = app.getAppPath(); if (!isDevMode()) {