ente/main/utils/appUpdater.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-12-19 06:23:44 +00:00
import { BrowserWindow, dialog, Tray } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
2022-03-08 05:50:03 +00:00
import { setIsAppQuitting, setIsUpdateAvailable } from '..';
2021-12-19 06:23:44 +00:00
import { buildContextMenu } from './menuUtil';
2021-07-16 06:10:58 +00:00
2021-07-17 11:09:10 +00:00
class AppUpdater {
2021-12-19 06:23:44 +00:00
constructor() {
log.transports.file.level = 'debug';
autoUpdater.logger = log;
}
2021-07-16 06:10:58 +00:00
2021-12-19 06:23:44 +00:00
async checkForUpdate(tray: Tray, mainWindow: BrowserWindow) {
await autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('update-downloaded', () => {
showUpdateDialog();
setIsUpdateAvailable(true);
tray.setContextMenu(buildContextMenu(mainWindow));
});
}
2021-07-16 06:10:58 +00:00
}
2021-07-17 11:09:10 +00:00
export default new AppUpdater();
2021-07-16 06:10:58 +00:00
2021-12-19 06:23:44 +00:00
export const showUpdateDialog = (): void => {
dialog
.showMessageBox({
type: 'info',
title: 'Install update',
message: 'Restart to update to the latest version of ente',
buttons: ['Later', 'Restart now'],
2021-12-19 06:23:44 +00:00
})
.then((buttonIndex) => {
if (buttonIndex.response === 1) {
setIsAppQuitting(true);
autoUpdater.quitAndInstall();
}
});
};