Skip to content

Commit c09b8f6

Browse files
committed
update additional paths
1 parent 5603b4e commit c09b8f6

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/main/main.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { app, Menu, MenuItem } from 'electron';
2-
import log, { LevelOption } from 'electron-log';
2+
3+
// Update paths to prevent Snap saving persistent data to version specific paths.
4+
// (Must be called before any other initialization)
5+
updatePathsForSnap();
6+
37
import * as fs from 'fs';
48
import * as semver from 'semver';
59
import {
@@ -9,19 +13,14 @@ import {
913
getBundledPythonPath,
1014
installBundledEnvironment,
1115
isDevMode,
12-
isSnap,
1316
jlabCLICommandIsSetup,
1417
setupJlabCommandWithUserRights,
1518
versionWithoutSuffix,
1619
waitForDuration,
1720
waitForFunction
1821
} from './utils';
1922

20-
if (isSnap()) {
21-
app.setPath('home', process.env.HOME);
22-
app.setPath('userData', `${process.env.HOME}/.config/${app.getName()}`);
23-
}
24-
23+
import log, { LevelOption } from 'electron-log';
2524
import { JupyterApplication } from './app';
2625
import { ICLIArguments } from './tokens';
2726
import { SessionConfig } from './config/sessionconfig';
@@ -52,6 +51,32 @@ async function appReady(): Promise<boolean> {
5251
*/
5352
require('fix-path')();
5453

54+
/**
55+
* Update app home, appData, userData and logs paths to prevent
56+
* Snap to save Python environments and logs in version specific locations
57+
*/
58+
function updatePathsForSnap() {
59+
const isSnap = (): boolean => {
60+
return process.platform === 'linux' && process.env.SNAP !== undefined;
61+
};
62+
63+
if (!isSnap()) {
64+
return;
65+
}
66+
67+
const userHome = process.env.HOME;
68+
process.env.XDG_CONFIG_HOME = `${userHome}/.config`;
69+
// Jupyter uses this path (.local/share)
70+
process.env.XDG_DATA_HOME = `${userHome}/.local/share`;
71+
const appDataDir = process.env.XDG_CONFIG_HOME;
72+
const userDataDir = `${appDataDir}/${app.getName()}`;
73+
74+
app.setPath('home', userHome);
75+
app.setPath('appData', appDataDir);
76+
app.setPath('userData', userDataDir);
77+
app.setAppLogsPath(`${userDataDir}/logs`);
78+
}
79+
5580
function getLogLevel(): LevelOption {
5681
if (isDevMode()) {
5782
return 'debug';

src/main/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ export function isDevMode(): boolean {
3030
return require.main.filename.indexOf('app.asar') === -1;
3131
}
3232

33-
export function isSnap(): boolean {
34-
return process.platform === 'linux' && process.env.SNAP !== undefined;
35-
}
36-
3733
export function getAppDir(): string {
3834
let appDir = app.getAppPath();
3935
if (!isDevMode()) {

0 commit comments

Comments
 (0)