-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
55 lines (45 loc) · 1.42 KB
/
Copy pathmain.ts
File metadata and controls
55 lines (45 loc) · 1.42 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { app, BrowserWindow, ipcMain } from 'electron';
import { Eimer, EimerIpcMainTransport } from 'eimer';
import * as path from 'path';
let mainWindow: BrowserWindow;
// Set up main process node
const eimer = new Eimer('main');
// Set up counter state in main process
let counter = Math.round(Math.random() * 100);
// Handle increment/decrement RPC calls
eimer.registerRpcHandler('counter.increment', async () => {
counter += 1;
eimer.publish('counter.change', counter);
return counter;
});
eimer.registerRpcHandler('counter.decrement', async () => {
counter -= 1;
eimer.publish('counter.change', counter);
return counter;
});
eimer.registerRpcHandler('counter.get', async () => {
console.log('counter', counter);
return counter;
});
// Start the app
app.whenReady().then(() => {
// Create main window
mainWindow = new BrowserWindow({
width: 1440,
height: 600,
webPreferences: {
sandbox: true,
preload: path.join(__dirname, 'preload.js')
}
});
// connect eimer to preload/renderer via ipcMain
eimer.connect(new EimerIpcMainTransport(ipcMain, mainWindow.webContents));
// Load the renderer
mainWindow.loadFile(path.join(__dirname, '../index.html'));
mainWindow.webContents.openDevTools();
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
});