mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
fix: better error handling on updation fails
- ask user whether to restart post update download
This commit is contained in:
parent
a8e681b973
commit
cd234f8826
@ -5,7 +5,7 @@ import { getSchemas } from '../../schemas';
|
||||
import {
|
||||
databaseMethodSet,
|
||||
emitMainProcessError,
|
||||
unlinkIfExists
|
||||
unlinkIfExists,
|
||||
} from '../helpers';
|
||||
import patches from '../patches';
|
||||
import { BespokeQueries } from './bespoke';
|
||||
|
@ -51,8 +51,11 @@ export const databaseMethodSet: Set<DatabaseMethod> = new Set([
|
||||
'exists',
|
||||
]);
|
||||
|
||||
export function emitMainProcessError(error: unknown) {
|
||||
(process.emit as Function)(CUSTOM_EVENTS.MAIN_PROCESS_ERROR, error);
|
||||
export function emitMainProcessError(
|
||||
error: unknown,
|
||||
more?: Record<string, unknown>
|
||||
) {
|
||||
(process.emit as Function)(CUSTOM_EVENTS.MAIN_PROCESS_ERROR, error, more);
|
||||
}
|
||||
|
||||
export async function checkFileAccess(filePath: string, mode?: number) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { emitMainProcessError } from 'backend/helpers';
|
||||
import { app, dialog } from 'electron';
|
||||
import { autoUpdater, UpdateInfo } from 'electron-updater';
|
||||
import { Main } from '../main';
|
||||
import { IPC_CHANNELS } from '../utils/messages';
|
||||
|
||||
export default function registerAutoUpdaterListeners(main: Main) {
|
||||
autoUpdater.autoDownload = false;
|
||||
@ -13,11 +13,7 @@ export default function registerAutoUpdaterListeners(main: Main) {
|
||||
return;
|
||||
}
|
||||
|
||||
main.mainWindow!.webContents.send(IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR, error);
|
||||
dialog.showErrorBox(
|
||||
'Update Error: ',
|
||||
error == null ? 'unknown' : (error.stack || error).toString()
|
||||
);
|
||||
emitMainProcessError(error);
|
||||
});
|
||||
|
||||
autoUpdater.on('update-available', async (info: UpdateInfo) => {
|
||||
@ -30,7 +26,7 @@ export default function registerAutoUpdaterListeners(main: Main) {
|
||||
if (!isCurrentBeta && isNextBeta) {
|
||||
const option = await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: `Update Frappe Books?`,
|
||||
title: 'Update Available',
|
||||
message: `Download version ${nextVersion}?`,
|
||||
buttons: ['Yes', 'No'],
|
||||
});
|
||||
@ -44,4 +40,19 @@ export default function registerAutoUpdaterListeners(main: Main) {
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { emitMainProcessError } from 'backend/helpers';
|
||||
import { app, dialog, ipcMain } from 'electron';
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
import fs from 'fs/promises';
|
||||
@ -52,10 +53,16 @@ export default function registerIpcMainActionListeners(main: Main) {
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, async () => {
|
||||
if (!main.isDevelopment && !main.checkedForUpdate) {
|
||||
await autoUpdater.checkForUpdates();
|
||||
main.checkedForUpdate = true;
|
||||
if (main.isDevelopment || main.checkedForUpdate) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await autoUpdater.checkForUpdates();
|
||||
} catch (error) {
|
||||
emitMainProcessError(error);
|
||||
}
|
||||
main.checkedForUpdate = true;
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_ACTIONS.GET_LANGUAGE_MAP, async (event, code) => {
|
||||
|
@ -17,10 +17,11 @@ export default function registerProcessListeners(main: Main) {
|
||||
}
|
||||
}
|
||||
|
||||
process.on(CUSTOM_EVENTS.MAIN_PROCESS_ERROR, (error) => {
|
||||
process.on(CUSTOM_EVENTS.MAIN_PROCESS_ERROR, (error, more) => {
|
||||
main.mainWindow!.webContents.send(
|
||||
IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR,
|
||||
error
|
||||
error,
|
||||
more
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -4,13 +4,16 @@ import { fyo } from 'src/initFyo';
|
||||
import { IPC_CHANNELS } from 'utils/messages';
|
||||
|
||||
export default function registerIpcRendererListeners() {
|
||||
ipcRenderer.on(IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR, async (_, error) => {
|
||||
if (fyo.store.isDevelopment) {
|
||||
console.error(error);
|
||||
}
|
||||
ipcRenderer.on(
|
||||
IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR,
|
||||
async (_, error, more) => {
|
||||
if (fyo.store.isDevelopment) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
await handleError(true, error as Error);
|
||||
});
|
||||
await handleError(true, error as Error, more);
|
||||
}
|
||||
);
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.CONSOLE_LOG, (_, ...stuff: unknown[]) => {
|
||||
if (!fyo.store.isDevelopment) {
|
||||
|
Loading…
Reference in New Issue
Block a user