2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 19:29:02 +00:00
books/main/registerAutoUpdaterListeners.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.6 KiB
TypeScript
Raw Normal View History

import { emitMainProcessError } from 'backend/helpers';
2022-08-26 10:39:43 +00:00
import { app, dialog } from 'electron';
import { autoUpdater, UpdateInfo } from 'electron-updater';
import { Main } from '../main';
import { isNetworkError } from './helpers';
export default function registerAutoUpdaterListeners(main: Main) {
2022-08-26 10:39:43 +00:00
autoUpdater.autoDownload = false;
autoUpdater.allowPrerelease = true;
2022-05-27 10:47:24 +00:00
autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.on('error', (error) => {
if (!main.checkedForUpdate) {
main.checkedForUpdate = true;
}
if (isNetworkError(error)) {
return;
}
emitMainProcessError(error);
2022-08-26 10:39:43 +00:00
});
autoUpdater.on('update-available', async (info: UpdateInfo) => {
const currentVersion = app.getVersion();
const nextVersion = info.version;
const isCurrentBeta = currentVersion.includes('beta');
const isNextBeta = nextVersion.includes('beta');
let downloadUpdate = true;
if (!isCurrentBeta && isNextBeta) {
const option = await dialog.showMessageBox({
type: 'info',
title: 'Update Available',
2022-08-26 10:39:43 +00:00
message: `Download version ${nextVersion}?`,
buttons: ['Yes', 'No'],
});
downloadUpdate = option.response === 0;
}
if (!downloadUpdate) {
return;
}
await autoUpdater.downloadUpdate();
});
autoUpdater.on('update-downloaded', async () => {
const option = await dialog.showMessageBox({
type: 'info',
title: 'Update Downloaded',
message: 'Restart Frappe Books to install update?',
buttons: ['Yes', 'No'],
});
if (option.response === 1) {
return;
}
autoUpdater.quitAndInstall();
});
}