mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
fix: ask if should update
- if next version is beta and !current
This commit is contained in:
parent
e65f69b5d5
commit
c8f5c0123f
@ -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;
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user