From 8dc1d10bc3cbe8a80a48c04cd98b75e62ed1de00 Mon Sep 17 00:00:00 2001 From: iishiishii Date: Mon, 21 Oct 2024 07:18:45 +1000 Subject: [PATCH] fixed #43, workaround relaunch to keep privilege for child process --- src/main/app.ts | 4 ++++ src/main/utils.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/app.ts b/src/main/app.ts index a59e06f2..4dc4cde7 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -18,6 +18,7 @@ import * as semver from 'semver'; import * as fs from 'fs'; import { clearSession, + customRelaunch, getAppDir, getBundledPythonEnvPath, getBundledPythonPath, @@ -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(); }); diff --git a/src/main/utils.ts b/src/main/utils.ts index acf3fb9f..cb767a65 100644 --- a/src/main/utils.ts +++ b/src/main/utils.ts @@ -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'; @@ -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(); +}