Skip to content

Commit 050a5f6

Browse files
Install updates silently and relaunch (#217)
Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent 8f50074 commit 050a5f6

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

electron-builder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ nsis:
4848
oneClick: false
4949
perMachine: true
5050
allowElevation: true
51+
runAfterFinish: true
5152
differentialPackage: false
5253
artifactName: Switchify-PC-Setup-${version}-${arch}.${ext}

src/main/updates/update-service.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('UpdateService', () => {
138138
expect(updater.quitAndInstall).not.toHaveBeenCalled();
139139
});
140140

141-
it('calls quitAndInstall after an update is downloaded', async () => {
141+
it('installs downloaded updates silently and relaunches the app', async () => {
142142
const updater = new FakeUpdater();
143143
updater.checkForUpdates.mockImplementation(async () => {
144144
updater.emit('update-available', updateInfo({ version: '0.1.1' }));
@@ -153,7 +153,7 @@ describe('UpdateService', () => {
153153
await service.downloadUpdate();
154154

155155
expect(service.installDownloadedUpdate()).toEqual({ ok: true });
156-
expect(updater.quitAndInstall).toHaveBeenCalledWith(false, true);
156+
expect(updater.quitAndInstall).toHaveBeenCalledWith(true, true);
157157
});
158158

159159
it('maps updater errors during checks to check_failed', async () => {

src/main/updates/update-service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export type UpdateServiceOptions = {
2828

2929
type UpdateOperation = 'idle' | 'checking' | 'downloading';
3030

31+
const INSTALL_UPDATE_SILENTLY = true;
32+
const FORCE_RUN_AFTER_INSTALL = true;
33+
3134
export class UpdateService {
3235
private readonly isPackaged: boolean;
3336
private readonly platform: NodeJS.Platform;
@@ -182,7 +185,7 @@ export class UpdateService {
182185
return { ok: false, reason: 'not_downloaded' };
183186
}
184187

185-
this.autoUpdater.quitAndInstall(false, true);
188+
this.autoUpdater.quitAndInstall(INSTALL_UPDATE_SILENTLY, FORCE_RUN_AFTER_INSTALL);
186189
return { ok: true };
187190
}
188191

src/renderer/components/UpdatesPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function UpdatesPanel({
5656
) : null}
5757
{showInstallButton ? (
5858
<button type="button" className="primary-button" onClick={() => void onInstallDownloaded()}>
59-
Install update
59+
Install and restart
6060
</button>
6161
) : null}
6262
</div>

0 commit comments

Comments
 (0)