improve launcher session logout and update restart

This commit is contained in:
2026-07-06 09:55:15 +09:00
parent a0b0e3cfb8
commit 5dba1bb084
3 changed files with 50 additions and 17 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "autonomy-studio-launcher", "name": "autonomy-studio-launcher",
"version": "1.0.11", "version": "1.0.12",
"description": "Autonomy Studio v2 Frontend", "description": "Autonomy Studio v2 Frontend",
"main": "./out/main/index.js", "main": "./out/main/index.js",
"author": { "author": {
+46 -15
View File
@@ -294,6 +294,48 @@ function installDebPackage(debPath: string): Promise<void> {
}) })
} }
function createCleanChildEnv(extraEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const env = { ...process.env, ...extraEnv }
delete env.APPIMAGE
delete env.APPDIR
delete env.OWD
delete env.ARGV0
delete env.ELECTRON_RENDERER_URL
delete env.VITE_DEV_SERVER_URL
return env
}
function stopChildApps(
appProcesses: Map<string, ChildProcess>,
appWindows: Map<string, BrowserWindow>,
): void {
for (const child of appProcesses.values()) {
if (!child.killed) {
child.kill('SIGTERM')
setTimeout(() => {
if (!child.killed) child.kill('SIGKILL')
}, 1500).unref()
}
}
appProcesses.clear()
for (const win of appWindows.values()) {
if (!win.isDestroyed()) win.close()
}
appWindows.clear()
}
function relaunchFromCleanProcess(): void {
const child = spawn('/bin/sh', ['-lc', 'sleep 1; exec "$LAUNCHER_PATH" >/dev/null 2>&1'], {
detached: true,
stdio: 'ignore',
env: createCleanChildEnv({ LAUNCHER_PATH: process.execPath }),
})
child.unref()
}
function runCommand(command: string, args: string[], timeoutMs = 30000, extraEnv?: NodeJS.ProcessEnv): Promise<{ stdout: string; stderr: string }> { function runCommand(command: string, args: string[], timeoutMs = 30000, extraEnv?: NodeJS.ProcessEnv): Promise<{ stdout: string; stderr: string }> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const child = spawn(command, args, { const child = spawn(command, args, {
@@ -775,20 +817,12 @@ function createWindow(): void {
await installDebPackage(debPath) await installDebPackage(debPath)
if (!is.dev) { if (!is.dev) {
for (const child of appProcesses.values()) { stopChildApps(appProcesses, appWindows)
child.kill()
}
appProcesses.clear()
for (const win of appWindows.values()) {
if (!win.isDestroyed()) win.close()
}
appWindows.clear()
setImmediate(() => { setImmediate(() => {
app.relaunch() relaunchFromCleanProcess()
app.quit() app.quit()
setTimeout(() => app.exit(0), 1000) setTimeout(() => app.exit(0), 1000).unref()
}) })
} }
@@ -881,7 +915,7 @@ function createWindow(): void {
: [...launchUrlArg, ...authLaunchArgs, ...(authProtocolUrl ? [authProtocolUrl] : [])] : [...launchUrlArg, ...authLaunchArgs, ...(authProtocolUrl ? [authProtocolUrl] : [])]
const execBin = useDevLauncher ? 'npm' : spawnPath const execBin = useDevLauncher ? 'npm' : spawnPath
const childEnv = { ...process.env } const childEnv = createCleanChildEnv()
if (useDevLauncher && url) { if (useDevLauncher && url) {
childEnv.ATNMY_APP_URL = url childEnv.ATNMY_APP_URL = url
} }
@@ -894,9 +928,6 @@ function createWindow(): void {
childEnv.ATNMY_AUDIENCE_APP = audienceApp childEnv.ATNMY_AUDIENCE_APP = audienceApp
} }
delete childEnv.ELECTRON_RENDERER_URL
delete childEnv.VITE_DEV_SERVER_URL
const logPath = useDevLauncher ? join(app.getPath('temp'), `autonomy-studio-${appName.replace(/[^a-z0-9_-]+/gi, '-').toLowerCase()}.dev.log`) : undefined const logPath = useDevLauncher ? join(app.getPath('temp'), `autonomy-studio-${appName.replace(/[^a-z0-9_-]+/gi, '-').toLowerCase()}.dev.log`) : undefined
const logFd = logPath ? openSync(logPath, 'a') : undefined const logFd = logPath ? openSync(logPath, 'a') : undefined
if (logPath) { if (logPath) {
+3 -1
View File
@@ -32,16 +32,18 @@ function App(): React.JSX.Element {
}, []) }, [])
const handleLogout = useCallback((): void => { const handleLogout = useCallback((): void => {
const accessToken = authSession?.accessToken
void fetch(`${LAUNCHER_API_BASE_URL}/api/auth/logout`, { void fetch(`${LAUNCHER_API_BASE_URL}/api/auth/logout`, {
method: 'POST', method: 'POST',
credentials: 'include', credentials: 'include',
keepalive: true, keepalive: true,
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : undefined,
}).catch(() => undefined) }).catch(() => undefined)
window.launcherTailscale?.logout().catch(() => undefined) window.launcherTailscale?.logout().catch(() => undefined)
window.localStorage.removeItem(AUTH_SESSION_KEY) window.localStorage.removeItem(AUTH_SESSION_KEY)
window.sessionStorage.removeItem(AUTH_SESSION_KEY) window.sessionStorage.removeItem(AUTH_SESSION_KEY)
setAuthSession(null) setAuthSession(null)
}, []) }, [authSession?.accessToken])
useEffect(() => { useEffect(() => {
if (!authSession?.accessToken) return if (!authSession?.accessToken) return