Skip to content

Commit 38e6295

Browse files
authored
Merge pull request #801 from jupyterlab/set-snap-home-to-user-home
set Snap home and userData directories to user directories
2 parents 3ad2551 + c09b8f6 commit 38e6295

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/main/main.ts

Lines changed: 33 additions & 1 deletion
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 {
@@ -15,6 +19,8 @@ import {
1519
waitForDuration,
1620
waitForFunction
1721
} from './utils';
22+
23+
import log, { LevelOption } from 'electron-log';
1824
import { JupyterApplication } from './app';
1925
import { ICLIArguments } from './tokens';
2026
import { SessionConfig } from './config/sessionconfig';
@@ -45,6 +51,32 @@ async function appReady(): Promise<boolean> {
4551
*/
4652
require('fix-path')();
4753

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+
4880
function getLogLevel(): LevelOption {
4981
if (isDevMode()) {
5082
return 'debug';

0 commit comments

Comments
 (0)