-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
63 lines (52 loc) · 1.92 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const path = require('path');
const { app, BrowserWindow, ipcMain } = require('electron');
const base = (process.env.NODE_ENV === 'dev') ? 'src' : 'lib'; // base dir
const {
MessageChannel, /* must required in index.js even if you don't use it */
BrowserService,
ChildProcessPool
} = require(`./${base}/index`);
// allow require native modules in renderer process
app.allowRendererProcessReuse = false;
const processManager = require(`./${base}/libs/ProcessManager`);
const entryHtml = path.join(__dirname, 'test/index.html');
const entryService = path.join(__dirname, 'test/services/app.service.js');
const otherService = path.join(__dirname, 'test/services/other.service.js');
/* 创建窗口 */
async function createWindow() {
global.mainWindow = new BrowserWindow({
show: false,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
},
});
await processManager.openWindow(process.env.NODE_ENV);
// processManager.openWindow('prod');
global.mainWindow.loadFile(entryHtml);
}
/* prepare to test */
app.whenReady().then(async() => {
global.appService = new BrowserService('app',
entryService,
{ dev: true, webPreferences: { webSecurity: false } }
);
global.otherService = new BrowserService('other',
otherService,
{ dev: true, webPreferences: { webSecurity: false } }
);
await global.appService.connected();
await global.otherService.connected();
/* service devtools */
// global.appService.openDevTools();
// global.otherService.openDevTools();
global.childProcessPool = new ChildProcessPool({
path: path.resolve(__dirname, './test/child_process/child1.js'),
max: 3
});
global.childProcessPool.send('test1', { value: 'test1' });
global.childProcessPool.send('test2', { value: 'test2' });
global.childProcessPool.send('test2', { value: 'test3' });
await createWindow();
});