mirror of
https://github.com/frappe/books.git
synced 2025-02-02 03:58:26 +00:00
feat: updation using notification flow
- minor refactor in errorHandling
This commit is contained in:
parent
0d3db0739a
commit
af0e8523ed
@ -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
|
||||
* ------------------------------*/
|
||||
|
@ -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) {
|
||||
|
83
src/main.js
83
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: '<App/>',
|
||||
});
|
||||
})();
|
||||
|
||||
function registerIpcRendererListeners() {
|
||||
ipcRenderer.on(IPC_CHANNELS.STORE_ON_WINDOW, (event, message) => {
|
||||
Object.assign(window.frappe.store, message);
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.CHECKING_FOR_UPDATE, (_) => {
|
||||
showToast({ message: frappe.t`Checking for updates` });
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_AVAILABLE, (_, version) => {
|
||||
const message = version
|
||||
? frappe.t`Version ${version} available`
|
||||
: frappe.t`New version available`;
|
||||
const action = () => {
|
||||
ipcRenderer.send(IPC_MESSAGES.DOWNLOAD_UPDATE);
|
||||
};
|
||||
|
||||
showToast({
|
||||
message,
|
||||
action,
|
||||
actionText: frappe.t`Download Update`,
|
||||
duration: 10_000,
|
||||
type: 'success',
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_NOT_AVAILABLE, (_) => {
|
||||
showToast({ message: frappe.t`No updates available` });
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_DOWNLOADED, (_) => {
|
||||
const action = () => {
|
||||
ipcRenderer.send(IPC_MESSAGES.INSTALL_UPDATE);
|
||||
};
|
||||
showToast({
|
||||
message: frappe.t`Update downloaded`,
|
||||
action,
|
||||
actionText: frappe.t`Install Update`,
|
||||
duration: 10_000,
|
||||
type: 'success',
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on(IPC_CHANNELS.UPDATE_ERROR, (_, error) => {
|
||||
error.name = 'Updation Error';
|
||||
handleError(true, error);
|
||||
});
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ export const IPC_MESSAGES = {
|
||||
RESIZE_MAIN_WINDOW: 'resize-main-window',
|
||||
CLOSE_CURRENT_WINDOW: 'close-current-window',
|
||||
MINIMIZE_CURRENT_WINDOW: 'minimize-current-window',
|
||||
DOWNLOAD_UPDATE: 'download-update',
|
||||
INSTALL_UPDATE: 'install-update',
|
||||
};
|
||||
|
||||
// ipcRenderer.invoke(...)
|
||||
@ -27,6 +29,11 @@ export const IPC_ACTIONS = {
|
||||
// ipcMain.send(...)
|
||||
export const IPC_CHANNELS = {
|
||||
STORE_ON_WINDOW: 'store-on-window',
|
||||
CHECKING_FOR_UPDATE: 'checking-for-update',
|
||||
UPDATE_AVAILABLE: 'update-available',
|
||||
UPDATE_NOT_AVAILABLE: 'update-not-available',
|
||||
UPDATE_DOWNLOADED: 'update-downloaded',
|
||||
UPDATE_ERROR: 'update-error',
|
||||
};
|
||||
|
||||
export const DB_CONN_FAILURE = {
|
||||
|
@ -11,7 +11,7 @@
|
||||
<div class="flex flex-row justify-end my-4">
|
||||
<button
|
||||
class="text-gray-900 text-sm hover:bg-gray-100 rounded-md px-4 py-1.5"
|
||||
@click="checkForUpdates"
|
||||
@click="checkForUpdates(true)"
|
||||
>
|
||||
Check for Updates
|
||||
</button>
|
||||
@ -45,9 +45,7 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
checkForUpdates() {
|
||||
checkForUpdates(true);
|
||||
},
|
||||
checkForUpdates,
|
||||
forwardChangeEvent(...args) {
|
||||
this.$emit('change', ...args);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user