Skip to content

Commit

Permalink
change updater to test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanfbrito committed Apr 12, 2023
1 parent fcd082f commit 972f141
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/updates/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';

import { app } from 'electron';
import { BrowserWindow, app, autoUpdater as nativeUpdater } from 'electron';
import { autoUpdater } from 'electron-updater';

import { listen, dispatch, select } from '../store';
Expand Down Expand Up @@ -214,6 +214,14 @@ export const setupUpdates = async (): Promise<void> => {
dispatch({ type: UPDATES_NEW_VERSION_NOT_AVAILABLE });
});

const nativeUpdateDownloadedCallback = () => {
nativeUpdater.removeListener(
'update-downloaded',
nativeUpdateDownloadedCallback
);
nativeUpdater.quitAndInstall();
};

autoUpdater.addListener('update-downloaded', async () => {
const response = await askUpdateInstall();

Expand All @@ -223,8 +231,16 @@ export const setupUpdates = async (): Promise<void> => {
}

try {
app.removeAllListeners('window-all-closed');
autoUpdater.quitAndInstall(true, true);
setImmediate(() => {
app.removeAllListeners('window-all-closed');
const allBrowserWindows = BrowserWindow.getAllWindows();
allBrowserWindows.forEach((browserWindow) => {
browserWindow.removeAllListeners('close');
browserWindow.destroy();
});
nativeUpdater.checkForUpdates();
nativeUpdater.on('update-downloaded', nativeUpdateDownloadedCallback);
});
} catch (error) {
error instanceof Error &&
dispatch({
Expand Down

0 comments on commit 972f141

Please sign in to comment.