feat: auto-restart after update with 3s countdown, remove manual restart button
Some checks failed
Build & Release / build (push) Failing after 54s
Some checks failed
Build & Release / build (push) Failing after 54s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
79050a43b3
commit
a30cdd0538
2 changed files with 16 additions and 12 deletions
|
|
@ -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');
|
||||
</script></body></html>`;
|
||||
|
||||
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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<void>((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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue