From a30cdd05383af151ea499cf6a3cea9d3ae5a22f4 Mon Sep 17 00:00:00 2001 From: MiTHRAL Date: Wed, 22 Apr 2026 01:59:38 -0400 Subject: [PATCH] feat: auto-restart after update with 3s countdown, remove manual restart button Co-Authored-By: Claude Sonnet 4.6 --- src/native/update-window.ts | 24 ++++++++++++++---------- src/native/updater.ts | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/native/update-window.ts b/src/native/update-window.ts index 8f5dc08..5206ea5 100644 --- a/src/native/update-window.ts +++ b/src/native/update-window.ts @@ -27,17 +27,22 @@ ipcRenderer.on('upd-progress',(_,p)=>{ document.getElementById('status').textContent=p<100?'Downloading… '+p+'%':'Installing…'; }); ipcRenderer.on('upd-ready',(_,v)=>{ - document.getElementById('title').textContent='Sanctum '+v+' Ready'; - document.getElementById('status').textContent='Restart to apply the update.'; + document.getElementById('title').textContent='Sanctum '+v+' installed'; document.getElementById('bar').style.width='100%'; - document.getElementById('btn').style.display='block'; + var s=document.getElementById('status'); + var n=2; + s.textContent='Restarting in '+n+'…'; + var t=setInterval(function(){ + n--; + if(n<=0){clearInterval(t);s.textContent='Restarting…';} + else s.textContent='Restarting in '+n+'…'; + },1000); }); ipcRenderer.on('upd-error',(_,msg)=>{ document.getElementById('title').textContent='Update Failed'; document.getElementById('status').textContent=msg; document.getElementById('bar').style.background='#f38ba8'; }); -document.getElementById('btn').onclick=()=>ipcRenderer.send('upd-restart'); `; export function showUpdateWindow() { @@ -65,15 +70,14 @@ export function setUpdateProgress(percent: number) { win?.webContents.send("upd-progress", Math.round(percent)); } -export function setUpdateReady(version: string) { +export function setUpdateReady(version: string, relaunch: boolean) { win?.webContents.send("upd-ready", version); + setTimeout(() => { + if (relaunch) app.relaunch(); + app.exit(0); + }, 3000); } export function setUpdateError(msg: string) { win?.webContents.send("upd-error", msg); } - -ipcMain.on("upd-restart", () => { - if (process.platform !== "win32") app.relaunch(); - app.exit(0); -}); diff --git a/src/native/updater.ts b/src/native/updater.ts index 1ad838b..1d9373f 100644 --- a/src/native/updater.ts +++ b/src/native/updater.ts @@ -125,7 +125,7 @@ async function downloadAndInstall(url: string, version: string) { windowsHide: false, }); child.unref(); - setUpdateReady(version); // restart button will just app.exit(0) — batch relaunches + setUpdateReady(version, false); // batch script handles relaunch } else { await new Promise((resolve, reject) => { const cmd = `unzip -o "${zipPath}" -d "${extractDir}" && SUBDIR=$(ls "${extractDir}" | head -1) && rm -f "${installDir}/sanctum" && cp -rT "${extractDir}/$SUBDIR" "${installDir}"`; @@ -134,7 +134,7 @@ async function downloadAndInstall(url: string, version: string) { else resolve(); }); }); - setUpdateReady(version); + setUpdateReady(version, true); } }