-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
63 lines (54 loc) · 1.49 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
const {
app, BrowserWindow, ipcMain, Menu
} = require('electron');
const fs = require('fs');
const path = require('path');
const electron_remote = require('@electron/remote/main');
electron_remote.initialize();
function createWindow () {
let sizePath = path.join(app.getAppPath(), '../../data/window-size.json');
let winSize = {width: 600, height: 480};
try {
if(!fs.existsSync(path.join(app.getAppPath(), '../../data/'))) {
fs.mkdirSync(path.join(app.getAppPath(), '../../data/'));
}
if(!fs.existsSync(sizePath)) {
fs.writeFileSync(sizePath, JSON.stringify({width: 600, height: 480}));
}
let data = JSON.parse(fs.readFileSync(sizePath));
winSize.width = +data.width;
winSize.height = +data.height;
} catch(err) {
console.error('Cannot load window size');
}
const win = new BrowserWindow({
width: winSize.width + (app.isPackaged ? 0 : 500),
height: winSize.height,
minWidth: 560,
minHeight: 400,
maximizable: false,
resizable: true,
frame: true,
autoHideMenuBar: false,
title: 'AVD Launcher',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
});
Menu.setApplicationMenu(null);
electron_remote.enable(win.webContents);
win.loadFile('index.html');
if(!app.isPackaged) win.webContents.openDevTools();
};
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});