From af0e8523ed50ed1191b4fbd5a3785abc84177595 Mon Sep 17 00:00:00 2001
From: 18alantom <2.alan.tom@gmail.com>
Date: Thu, 3 Feb 2022 15:33:21 +0530
Subject: [PATCH] feat: updation using notification flow - minor refactor in
errorHandling
---
src/background.js | 45 ++++++++++++++++-
src/errorHandling.ts | 16 ++++--
src/main.js | 83 ++++++++++++++++++++++++--------
src/messages.js | 7 +++
src/pages/Settings/TabSystem.vue | 6 +--
5 files changed, 125 insertions(+), 32 deletions(-)
diff --git a/src/background.js b/src/background.js
index afd3c8bc..6d0f1863 100644
--- a/src/background.js
+++ b/src/background.js
@@ -37,6 +37,10 @@ protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { secure: true, standard: true } },
]);
+if (isDevelopment) {
+ autoUpdater.logger = console;
+}
+
Store.initRenderer();
/* -----------------------------
@@ -147,6 +151,14 @@ ipcMain.on(IPC_MESSAGES.SHOW_ITEM_IN_FOLDER, (event, filePath) => {
return shell.showItemInFolder(filePath);
});
+ipcMain.on(IPC_MESSAGES.DOWNLOAD_UPDATE, (event) => {
+ autoUpdater.downloadUpdate();
+});
+
+ipcMain.on(IPC_MESSAGES.INSTALL_UPDATE, (event) => {
+ autoUpdater.quitAndInstall(true, true);
+});
+
/* ----------------------------------
* Register ipcMain function handlers
* ----------------------------------*/
@@ -201,12 +213,41 @@ ipcMain.handle(IPC_ACTIONS.SEND_ERROR, (event, bodyJson) => {
});
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, (event, force) => {
- if (force || (!isDevelopment && !checkedForUpdate)) {
- autoUpdater.checkForUpdatesAndNotify();
+ if (!isDevelopment && !checkedForUpdate) {
+ autoUpdater.checkForUpdates();
checkedForUpdate = true;
+ } else if (force) {
+ autoUpdater.checkForUpdates();
}
});
+/* ------------------------------
+ * Register autoUpdater events lis
+ * ------------------------------*/
+
+autoUpdater.autoDownload = false;
+autoUpdater.autoInstallOnAppQuit = false;
+
+autoUpdater.on('checking-for-update', () => {
+ mainWindow.webContents.send(IPC_CHANNELS.CHECKING_FOR_UPDATE);
+});
+
+autoUpdater.on('update-available', (info) => {
+ mainWindow.webContents.send(IPC_CHANNELS.UPDATE_AVAILABLE, info.version);
+});
+
+autoUpdater.on('update-not-available', () => {
+ mainWindow.webContents.send(IPC_CHANNELS.UPDATE_NOT_AVAILABLE);
+});
+
+autoUpdater.on('update-downloaded', () => {
+ mainWindow.webContents.send(IPC_CHANNELS.UPDATE_DOWNLOADED);
+});
+
+autoUpdater.on('error', (error) => {
+ mainWindow.webContents.send(IPC_CHANNELS.UPDATE_ERROR, error);
+});
+
/* ------------------------------
* Register app lifecycle methods
* ------------------------------*/
diff --git a/src/errorHandling.ts b/src/errorHandling.ts
index 3082f419..924632ec 100644
--- a/src/errorHandling.ts
+++ b/src/errorHandling.ts
@@ -58,6 +58,16 @@ function getToastProps(errorLogObj: ErrorLog, cb?: Function) {
return props;
}
+export function getErrorLogObject(error: Error, more: object = {}): ErrorLog {
+ const { name, stack, message } = error;
+ const errorLogObj = { name, stack, message, more };
+
+ // @ts-ignore
+ frappe.errorLog.push(errorLogObj);
+
+ return errorLogObj;
+}
+
export function handleError(
shouldLog: boolean,
error: Error,
@@ -72,11 +82,7 @@ export function handleError(
return;
}
- const { name, stack, message } = error;
- const errorLogObj: ErrorLog = { name, stack, message, more };
-
- // @ts-ignore
- frappe.errorLog.push(errorLogObj);
+ const errorLogObj = getErrorLogObject(error, more);
// @ts-ignore
if (frappe.SystemSettings?.autoReportErrors) {
diff --git a/src/main.js b/src/main.js
index 87432a48..ba44833d 100644
--- a/src/main.js
+++ b/src/main.js
@@ -8,17 +8,7 @@ import { getErrorHandled, handleError } from './errorHandling';
import { IPC_CHANNELS, IPC_MESSAGES } from './messages';
import router from './router';
import { outsideClickDirective } from './ui';
-import { stringifyCircular } from './utils';
-
-function registerIpcRendererListeners() {
- ipcRenderer.on(IPC_CHANNELS.STORE_ON_WINDOW, (event, message) => {
- Object.assign(window.frappe.store, message);
- });
-
- ipcRenderer.on('wc-message', (event, message) => {
- console.log(message);
- });
-}
+import { showToast, stringifyCircular } from './utils';
(async () => {
frappe.isServer = true;
@@ -61,17 +51,19 @@ function registerIpcRendererListeners() {
});
Vue.config.errorHandler = (err, vm, info) => {
- const { fullPath, params } = vm.$route;
- const data = stringifyCircular(vm.$data, true, true);
- const props = stringifyCircular(vm.$props, true, true);
-
- handleError(false, err, {
- fullPath,
- params: stringifyCircular(params),
- data,
- props,
+ const more = {
info,
- });
+ };
+
+ if (vm) {
+ const { fullPath, params } = vm.$route;
+ more.fullPath = fullPath;
+ more.params = stringifyCircular(params ?? {});
+ more.data = stringifyCircular(vm.$data ?? {}, true, true);
+ more.props = stringifyCircular(vm.$props ?? {}, true, true);
+ }
+
+ handleError(false, err, more);
console.error(err, vm, info);
};
@@ -98,3 +90,52 @@ function registerIpcRendererListeners() {
template: '