-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (43 loc) · 1.71 KB
/
app.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 {app, BrowserWindow, shell} = require('electron');
const Store = require('electron-store');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
function createWindow() {
let store = new Store({defaults: {windowBounds: {width: 800, height: 600, x: 0, y: 0}}});
let {width, height, x, y} = store.get('windowBounds');
win = new BrowserWindow({
icon: './dota2-inv.png',
width, height,
x, y,
minWidth: 1024, minHeight: 800,
show: false,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
win.loadFile('index.html');
win.setMenu(null);
//win.webContents.openDevTools();
win.once('ready-to-show', () => win.show());
// The BrowserWindow class extends the node.js core EventEmitter class, so we use that API
// to listen to events on the BrowserWindow. The resize event is emitted when the window size changes.
win.on('resize', () => store.set('windowBounds', win.getBounds()));
win.on('move', () => store.set('windowBounds', win.getBounds()));
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win.on('closed', () => win = null);
// Open URLs externally
win.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => app.quit());