2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

fix: ask if should update

- if next version is beta and !current
This commit is contained in:
18alantom 2022-07-26 19:23:56 +05:30
parent e65f69b5d5
commit c8f5c0123f

View File

@ -1,5 +1,5 @@
import { app, dialog, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import { autoUpdater, UpdateInfo } from 'electron-updater';
import fs from 'fs/promises';
import path from 'path';
import databaseManager from '../backend/database/manager';
@ -15,6 +15,40 @@ import {
} from './helpers';
import { saveHtmlAsPdf } from './saveHtmlAsPdf';
autoUpdater.autoDownload = false;
autoUpdater.on('error', (error) => {
dialog.showErrorBox(
'Update Error: ',
error == null ? 'unknown' : (error.stack || error).toString()
);
});
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 Frappe Books?`,
message: `Download version ${nextVersion}?`,
buttons: ['Yes', 'No'],
});
downloadUpdate = option.response === 0;
}
if (!downloadUpdate) {
return;
}
await autoUpdater.downloadUpdate();
});
export default function registerIpcMainActionListeners(main: Main) {
ipcMain.handle(IPC_ACTIONS.GET_OPEN_FILEPATH, async (event, options) => {
return await dialog.showOpenDialog(main.mainWindow!, options);
@ -51,9 +85,9 @@ export default function registerIpcMainActionListeners(main: Main) {
sendError(bodyJson);
});
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, () => {
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, async () => {
if (!main.isDevelopment && !main.checkedForUpdate) {
autoUpdater.checkForUpdates();
await autoUpdater.checkForUpdates();
main.checkedForUpdate = true;
}
});