fix(electron): preserve changelog on download + reliable restart-to-update
- useUpdateStore: keep sidecar-sourced body when merging fresh desktopInfo (electron-updater returns 'See release notes at ...' which clobbered it) - main.mjs: defer quitAndInstall/relaunch via setImmediate so IPC reply flushes first; wire update-downloaded and error events; log restart path
This commit is contained in:
@@ -1355,6 +1355,17 @@ const setupAutoUpdater = () => {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-downloaded', (info) => {
|
||||||
|
log.info(`[electron] update-downloaded version=${info?.version || 'unknown'}`);
|
||||||
|
if (state.pendingUpdate) {
|
||||||
|
state.pendingUpdate.downloaded = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('error', (err) => {
|
||||||
|
log.error('[electron] autoUpdater error', err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseRelevantChangelogNotes = async (fromVersion, toVersion) => {
|
const parseRelevantChangelogNotes = async (fromVersion, toVersion) => {
|
||||||
@@ -1892,14 +1903,26 @@ const handleInvoke = async (browserWindow, command, args = {}) => {
|
|||||||
}));
|
}));
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
case 'desktop_restart':
|
case 'desktop_restart': {
|
||||||
if (state.pendingUpdate?.downloaded && app.isPackaged) {
|
const applyUpdate = Boolean(state.pendingUpdate?.downloaded && app.isPackaged);
|
||||||
autoUpdater.quitAndInstall(false, true);
|
log.info(`[electron] desktop_restart applyUpdate=${applyUpdate} packaged=${app.isPackaged}`);
|
||||||
return null;
|
// Defer so the IPC reply flushes before the app starts shutting down.
|
||||||
}
|
// Without this, quitAndInstall() can race with the renderer's pending
|
||||||
app.relaunch();
|
// invoke and the restart appears to do nothing from the UI side.
|
||||||
app.exit(0);
|
setImmediate(() => {
|
||||||
|
try {
|
||||||
|
if (applyUpdate) {
|
||||||
|
autoUpdater.quitAndInstall(false, true);
|
||||||
|
} else {
|
||||||
|
app.relaunch();
|
||||||
|
app.exit(0);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log.error('[electron] desktop_restart failed', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
case 'desktop_get_lan_address':
|
case 'desktop_get_lan_address':
|
||||||
return await detectLanIPv4Address();
|
return await detectLanIPv4Address();
|
||||||
|
|||||||
@@ -244,6 +244,10 @@ export const useUpdateStore = create<UpdateStore>()((set, get) => ({
|
|||||||
? {
|
? {
|
||||||
...state.info,
|
...state.info,
|
||||||
...desktopInfo,
|
...desktopInfo,
|
||||||
|
// Keep the richer sidecar-sourced changelog; desktopInfo.body is
|
||||||
|
// often the bare "See release notes at..." fallback from the
|
||||||
|
// updater and would otherwise clobber the nice changelog.
|
||||||
|
body: state.info.body || desktopInfo.body,
|
||||||
available: state.info.available,
|
available: state.info.available,
|
||||||
}
|
}
|
||||||
: desktopInfo,
|
: desktopInfo,
|
||||||
|
|||||||
Reference in New Issue
Block a user