-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage.js
50 lines (45 loc) · 1.12 KB
/
page.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
const electron = require('electron');
const packageJson = require('./package.json');
const BrowserWindow = electron.BrowserWindow;
class Page {
get config () {
return {};
}
get loadURL () {
return '';
}
initWindow () {
this.window = new BrowserWindow(Object.assign({
title: '窗口名字',
width: 380,
height: 440,
resizable: false,
maximizable: false,
minimizable: false,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
show: false // 初始化的时候不显示
}, this.config));
this.window.on('close', this._onWindowClose.bind(this));
this.window.loadURL(this.loadURL);
this.webContents = this.window.webContents;
if (this._canOpenDevTools()) this.webContents.openDevTools();
}
open () {
if (this.window) {
this.window.show();
}
}
_canOpenDevTools () {
if (packageJson.env === 'dev' || packageJson.env === 'debug') return true;
return false;
}
_onWindowClose (e) {
this.window.hide();
e.preventDefault();
}
}
module.exports = Page