-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (60 loc) · 1.43 KB
/
main.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
64
65
const {BrowserWindow,app} = require('electron');
const url = require('url');
const path = require('path');
const uuid = require('uuid/v4');
const {dev} = require('./package');
//窗口全局引用
let mainWin = null;
let subWins = [];
const getUrl = (appName)=>{
return dev?`http://127.0.0.1:8082/${appName}`:require('url').format({
protocol: 'file',
slashes: true,
pathname: require('path').join(__dirname, '/dist/'+appName+'/index.html')
})
};
const createSubWins = ()=>{
const subWin = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
}
});
const subWinObj = {
key:uuid(),
win:subWin
};
subWins.push(subWinObj);
subWin.loadURL(getUrl('App2')).then(e=>{
if (e) throw e;
}).catch(e=>{
console.log(e)
});
subWin.on('closed',()=>{
mainWin = null;
subWins.filter(subWin=>subWin.key!==subWinObj.key);
})
};
const createMainWin = ()=>{
mainWin = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
}
});
mainWin.loadURL(getUrl('App')).then(e=>{
if (e) throw e;
}).catch(e=>{
console.log(e)
});
mainWin.on('closed',()=>{
mainWin = null;
app.quit();
})
};
app.on('ready',()=>{
createMainWin();
createSubWins();
});