1
1
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
+
3
7
import * as fs from 'fs' ;
4
8
import * as semver from 'semver' ;
5
9
import {
@@ -9,19 +13,14 @@ import {
9
13
getBundledPythonPath ,
10
14
installBundledEnvironment ,
11
15
isDevMode ,
12
- isSnap ,
13
16
jlabCLICommandIsSetup ,
14
17
setupJlabCommandWithUserRights ,
15
18
versionWithoutSuffix ,
16
19
waitForDuration ,
17
20
waitForFunction
18
21
} from './utils' ;
19
22
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' ;
25
24
import { JupyterApplication } from './app' ;
26
25
import { ICLIArguments } from './tokens' ;
27
26
import { SessionConfig } from './config/sessionconfig' ;
@@ -52,6 +51,32 @@ async function appReady(): Promise<boolean> {
52
51
*/
53
52
require ( 'fix-path' ) ( ) ;
54
53
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
+
55
80
function getLogLevel ( ) : LevelOption {
56
81
if ( isDevMode ( ) ) {
57
82
return 'debug' ;
0 commit comments