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-04-19 06:00:50 +00:00
|
|
|
import { setIsAppQuitting, setIsUpdateAvailable } from '../main';
|
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',
|
2022-07-11 13:06:05 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|