forked from MicroDroid/vuex-electron-ipc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (29 loc) · 913 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const VUEX_MUTATION = 'VUEX_MUTATION';
function registerVuexHub() {
const { BrowserWindow, ipcMain } = require('electron');
ipcMain.on(VUEX_MUTATION, (event, mutation) => {
const originWindow = event.sender.getOwnerBrowserWindow();
const windows = BrowserWindow.getAllWindows();
for (let win of windows)
// Loose equals is intended, idk why Electron does this uh.
if (win.id != originWindow.id)
win.webContents.send(VUEX_MUTATION, mutation);
});
}
function registerVuexNode(store) {
const { ipcRenderer } = require('electron');
store.subscribe((mutation) => {
if (!mutation.payload || !mutation.payload.__IPC_MUTATION)
ipcRenderer.send(VUEX_MUTATION, mutation);
});
ipcRenderer.on(VUEX_MUTATION, (event, mutation) => {
store.commit(mutation.type, {
...mutation.payload || [],
__IPC_MUTATION: true,
});
});
}
module.exports = {
registerVuexHub,
registerVuexNode,
};