2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

refactor: use channels for ipcMain to ipcRenderer

This commit is contained in:
18alantom 2022-02-03 13:26:29 +05:30
parent 2fef56459c
commit f42df70fb1
3 changed files with 22 additions and 7 deletions

View File

@ -16,7 +16,7 @@ import fs from 'fs/promises';
import path from 'path';
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
import { sendError } from './contactMothership';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
import { IPC_ACTIONS, IPC_CHANNELS, IPC_MESSAGES } from './messages';
import saveHtmlAsPdf from './saveHtmlAsPdf';
const isDevelopment = process.env.NODE_ENV !== 'production';
@ -104,7 +104,7 @@ function createWindow() {
});
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('store-on-window', {
mainWindow.webContents.send(IPC_CHANNELS.STORE_ON_WINDOW, {
appVersion: app.getVersion(),
});
});
@ -201,7 +201,7 @@ ipcMain.handle(IPC_ACTIONS.SEND_ERROR, (event, bodyJson) => {
});
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, (event, force) => {
if (!isDevelopment && !checkedForUpdate) {
if (force || (!isDevelopment && !checkedForUpdate)) {
autoUpdater.checkForUpdatesAndNotify();
checkedForUpdate = true;
}

View File

@ -5,11 +5,21 @@ import models from '../models';
import App from './App';
import FeatherIcon from './components/FeatherIcon';
import { getErrorHandled, handleError } from './errorHandling';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
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);
});
}
(async () => {
frappe.isServer = true;
frappe.isElectron = true;
@ -26,9 +36,7 @@ import { stringifyCircular } from './utils';
window.frappe = frappe;
window.frappe.store = {};
ipcRenderer.on('store-on-window', (event, message) => {
Object.assign(window.frappe.store, message);
});
registerIpcRendererListeners();
Vue.config.productionTip = false;
Vue.component('feather-icon', FeatherIcon);

View File

@ -1,3 +1,4 @@
// ipcRenderer.send(...)
export const IPC_MESSAGES = {
OPEN_MENU: 'open-menu',
OPEN_SETTINGS: 'open-settings',
@ -9,6 +10,7 @@ export const IPC_MESSAGES = {
MINIMIZE_CURRENT_WINDOW: 'minimize-current-window',
};
// ipcRenderer.invoke(...)
export const IPC_ACTIONS = {
TOGGLE_MAXIMIZE_CURRENT_WINDOW: 'toggle-maximize-current-window',
GET_OPEN_FILEPATH: 'open-dialog',
@ -22,6 +24,11 @@ export const IPC_ACTIONS = {
CHECK_FOR_UPDATES: 'check-for-updates',
};
// ipcMain.send(...)
export const IPC_CHANNELS = {
STORE_ON_WINDOW: 'store-on-window',
};
export const DB_CONN_FAILURE = {
INVALID_FILE: 'invalid-file',
CANT_OPEN: 'cant-open',