Skip to content

Commit

Permalink
Merge pull request #801 from jupyterlab/set-snap-home-to-user-home
Browse files Browse the repository at this point in the history
set Snap home and userData directories to user directories
  • Loading branch information
mbektas authored Mar 24, 2024
2 parents 3ad2551 + c09b8f6 commit 38e6295
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,6 +19,8 @@ import {
waitForDuration,
waitForFunction
} from './utils';

import log, { LevelOption } from 'electron-log';
import { JupyterApplication } from './app';
import { ICLIArguments } from './tokens';
import { SessionConfig } from './config/sessionconfig';
Expand Down Expand Up @@ -45,6 +51,32 @@ async function appReady(): Promise<boolean> {
*/
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';
Expand Down

0 comments on commit 38e6295

Please sign in to comment.