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 {
@@ -15,6 +19,8 @@ import {
15
19
waitForDuration ,
16
20
waitForFunction
17
21
} from './utils' ;
22
+
23
+ import log , { LevelOption } from 'electron-log' ;
18
24
import { JupyterApplication } from './app' ;
19
25
import { ICLIArguments } from './tokens' ;
20
26
import { SessionConfig } from './config/sessionconfig' ;
@@ -45,6 +51,32 @@ async function appReady(): Promise<boolean> {
45
51
*/
46
52
require ( 'fix-path' ) ( ) ;
47
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
+
48
80
function getLogLevel ( ) : LevelOption {
49
81
if ( isDevMode ( ) ) {
50
82
return 'debug' ;
0 commit comments