mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
refactor: use channels for ipcMain to ipcRenderer
This commit is contained in:
parent
2fef56459c
commit
f42df70fb1
@ -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;
|
||||
}
|
||||
|
16
src/main.js
16
src/main.js
@ -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);
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user