-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
114 lines (98 loc) · 2.71 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";
const path = require('path');
const glob = require('glob');
const electron = require('electron');
const app = electron.app;
const Menu = electron.menu;
const BrowserWindow = electron.BrowserWindow;
let mWnd = null;
const cfg = require('./app/config');
//if (process.mas) app.setName('Dot Live Editor');
function createWindow () {
let shouldQuit = makeSingleInstance();
if (shouldQuit) return app.quit();
require(path.join(__dirname, 'app/ipcmain.js'));
mWnd = new BrowserWindow({
width: cfg.wnd.w,
height: cfg.wnd.h,
minWidth: 1366,
minHeight: 768,
alwaysOnTop: false,
title: cfg.appName
});
mWnd.loadURL(path.join('file://', __dirname, '/', cfg.wnd.mainLayout));
// open dev tools
if(cfg.dev) {
mWnd.webContents.openDevTools();
mWnd.maximize();
require('devtron').install();
}
// init menu
initMenu(cfg);
mWnd.on('closed', function () {
mWnd = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mWnd === null) {
createWindow();
}
});
function makeSingleInstance () {
if (process.mas) return false;
return app.makeSingleInstance(function () {
if (mWnd) {
if (mWnd.isMinimized()) mWnd.restore();
mWnd.focus();
}
})
}
function initMenu(cfg) {
return undefined;
let tpl = Menu.buildFromTemplate([
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { BrowserWindow.getFocusedWindow().reloadIgnoringCache(); }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
},
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
},
]
}
]);
Menu.setApplicationMenu(tpl);
}