Skip to content

Commit

Permalink
fixed #43, workaround relaunch to keep privilege for child process
Browse files Browse the repository at this point in the history
  • Loading branch information
iishiishii committed Oct 20, 2024
1 parent 6d6cfd6 commit 8dc1d10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as semver from 'semver';
import * as fs from 'fs';
import {
clearSession,
customRelaunch,
getAppDir,
getBundledPythonEnvPath,
getBundledPythonPath,
Expand Down Expand Up @@ -838,6 +839,9 @@ export class JupyterApplication implements IApplication, IDisposable {
);

this._evm.registerEventHandler(EventTypeMain.RestartApp, _event => {
if (process.platform === 'linux') {
app.relaunch = customRelaunch;
}
app.relaunch();
app.quit();
});
Expand Down
17 changes: 17 additions & 0 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import log from 'electron-log';
import { AddressInfo, createServer, Socket } from 'net';
import { app, nativeTheme } from 'electron';
import { IPythonEnvironment } from './tokens';
import { spawn } from 'child_process';

export const DarkThemeBGColor = '#212121';
export const LightThemeBGColor = '#ffffff';
Expand Down Expand Up @@ -283,3 +284,19 @@ export function getLogFilePath(processType: 'main' | 'renderer' = 'main') {
);
}
}

export function customRelaunch(): void {
const script = `while kill -0 ${process.pid} 2>/dev/null; do
sleep 0.1
done
${process.argv.join(' ')} & disown
exit
`;
spawn('sh', ['-c', `"${script}"`], {
shell: true,
detached: true,
stdio: 'ignore'
});
// Exit the parent process
process.exit();
}

0 comments on commit 8dc1d10

Please sign in to comment.