fix(desktop): announce staged updates reliably and install them silently
Two separate reasons "Restart to update" only ever showed up after pressing "check for updates" by hand, and one reason the restart was unpleasant. 1. `update-downloaded` is a one-shot push to whichever page happens to be loaded. It is dropped when the window is in the tray (mainWindow is null), when the 10s post-launch check beats the web app's listener registration, and on every reload. Once an update is staged the poll latches off, so it was never re-announced — a manual check was the only way back. The main process already tracks this in recoveryStore, so expose it over IPC and have the banner ask on mount rather than rely on catching the event live. 2. UpdateBanner was only mounted in the mobile layout. On the desktop app the visible one was UpdateToast, which duplicated the same "update ready" card in untranslated English. Mount the banner on desktop too and reduce the toast to the failure case it does not share. 3. quitAndInstall() defaults to a non-silent install, so on Windows restarting meant clicking through the NSIS wizard. Pass silent + force-run-after, and switch the installer to one-click per-user, which is what lets the silent install proceed without an elevation prompt. The manual-download link in the failure toast pointed at the upstream GitHub repository, which is private for this fork and 404'd for everyone. Point it at the fork's Gitea releases, where the updater feed already lives. Regression test covers the case the live event never announced; verified by mutation that removing the status query fails it and nothing else. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,5 +58,15 @@ linux:
|
||||
- deb
|
||||
category: Network
|
||||
nsis:
|
||||
oneClick: false
|
||||
allowToChangeInstallationDirectory: true
|
||||
# One-click, per-user install (%LOCALAPPDATA%), the way Discord ships.
|
||||
#
|
||||
# This is what makes an update silent: a per-user install needs no elevation,
|
||||
# so electron-updater can run the installer with /S and no UAC prompt breaks
|
||||
# the flow. The assisted installer we had before (oneClick: false) showed its
|
||||
# wizard on every update and offered an all-users install, which would then
|
||||
# demand elevation on each subsequent update.
|
||||
#
|
||||
# The trade is that a fresh install no longer asks where to put the app.
|
||||
oneClick: true
|
||||
perMachine: false
|
||||
allowToChangeInstallationDirectory: false
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
buildTrayMenuTemplate,
|
||||
buildAppMenuTemplate,
|
||||
type RecoveryState,
|
||||
RELEASES_URL,
|
||||
} from './recovery';
|
||||
import { migrateUserData } from './userDataMigration';
|
||||
|
||||
@@ -681,12 +682,25 @@ function registerIpcHandlers(): void {
|
||||
ipcMain.on('install-update', () => {
|
||||
try {
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
autoUpdater.quitAndInstall();
|
||||
quitAndInstallSilently(autoUpdater);
|
||||
} catch {
|
||||
// Auto-updater not available
|
||||
}
|
||||
});
|
||||
|
||||
// The `update-downloaded` push is a one-shot: it reaches whatever page is
|
||||
// loaded at that instant, and nothing else. It is lost when the window is in
|
||||
// the tray (destroyed), when the check lands before the web app has mounted
|
||||
// its listener, and on every reload. Since `downloaded` also latches off
|
||||
// further polls, the banner could then never appear at all — which is why
|
||||
// pressing "check for updates" by hand looked like the only thing that
|
||||
// worked. The renderer now asks for the current state on mount instead of
|
||||
// relying solely on catching the event live.
|
||||
ipcMain.handle('get-update-status', () => {
|
||||
const s = recoveryStore.get();
|
||||
return { state: s.updateState, version: s.updateVersion };
|
||||
});
|
||||
|
||||
ipcMain.on('check-for-updates', () => {
|
||||
try {
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
@@ -811,6 +825,22 @@ function registerIpcHandlers(): void {
|
||||
|
||||
// ─── Auto-Update ────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Installs a staged update with no installer UI and relaunches the app.
|
||||
*
|
||||
* `quitAndInstall()` defaults to (isSilent=false, isForceRunAfter=false): on
|
||||
* Windows that runs the NSIS installer with its full wizard, so "restart to
|
||||
* update" meant clicking through a setup program. Silent mode passes /S and
|
||||
* reuses the recorded install location; isForceRunAfter brings the app back up
|
||||
* afterwards, which the wizard would otherwise leave to a checkbox.
|
||||
*
|
||||
* Both flags are inert on macOS and Linux, where the update is applied by
|
||||
* swapping files — no installer runs either way.
|
||||
*/
|
||||
function quitAndInstallSilently(au: { quitAndInstall: (isSilent?: boolean, isForceRunAfter?: boolean) => void }): void {
|
||||
au.quitAndInstall(true, true);
|
||||
}
|
||||
|
||||
function initAutoUpdater(): void {
|
||||
try {
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
@@ -862,7 +892,7 @@ function initAutoUpdater(): void {
|
||||
showNotification(
|
||||
'Resenhacord update ready',
|
||||
`Click to restart and install version ${version}.`,
|
||||
() => autoUpdater.quitAndInstall(),
|
||||
() => quitAndInstallSilently(autoUpdater),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -885,7 +915,7 @@ function initAutoUpdater(): void {
|
||||
if (updateConfirmed) {
|
||||
mainWindow?.webContents.send('update-error', {
|
||||
message,
|
||||
releaseUrl: 'https://github.com/TheZwiss/backspace/releases/latest',
|
||||
releaseUrl: RELEASES_URL,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,6 +39,7 @@ contextBridge.exposeInMainWorld('backspace', {
|
||||
checkForUpdates: () => {
|
||||
ipcRenderer.send('check-for-updates');
|
||||
},
|
||||
getUpdateStatus: () => ipcRenderer.invoke('get-update-status'),
|
||||
getVersion: () => ipcRenderer.invoke('get-app-version'),
|
||||
|
||||
// Window focus
|
||||
|
||||
@@ -17,6 +17,15 @@ export type UpdateState =
|
||||
| 'downloaded'
|
||||
| 'error';
|
||||
|
||||
/**
|
||||
* Where a manual download lands when auto-update fails.
|
||||
*
|
||||
* The upstream GitHub repository this used to point at is private for this
|
||||
* fork, so the link 404'd for everyone who followed it. Releases are on the
|
||||
* fork's own Gitea, which is also where the updater feed lives.
|
||||
*/
|
||||
export const RELEASES_URL = 'https://git.resenha.website/devsyncwrld/backspace/releases';
|
||||
|
||||
export interface RecoveryState {
|
||||
mode: 'normal' | 'recovery';
|
||||
reason: { code: RecoveryReasonCode; detail: string } | null;
|
||||
@@ -419,7 +428,8 @@ export function handleRecoveryAction(action: RecoveryAction): void {
|
||||
// Direct quitAndInstall — does NOT rely on autoInstallOnAppQuit.
|
||||
// Force-kill-fix: if user reaches recovery and clicks here, install
|
||||
// happens cleanly even if the on-quit hook would otherwise be bypassed.
|
||||
autoUpdaterRef?.quitAndInstall();
|
||||
// Silent + relaunch, matching the in-app banner: no installer wizard.
|
||||
autoUpdaterRef?.quitAndInstall(true, true);
|
||||
return;
|
||||
}
|
||||
case 'change-instance': {
|
||||
@@ -440,7 +450,7 @@ export function handleRecoveryAction(action: RecoveryAction): void {
|
||||
return;
|
||||
}
|
||||
case 'open-releases': {
|
||||
shell.openExternal('https://github.com/TheZwiss/backspace/releases/latest');
|
||||
shell.openExternal(RELEASES_URL);
|
||||
return;
|
||||
}
|
||||
case 'quit': {
|
||||
|
||||
Reference in New Issue
Block a user