This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.js
84 lines (67 loc) · 2.01 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
require('coffee-script/register');
var app = require('app');
var shell = require('shell');
var BrowserWindow = require('browser-window');
var windowStateKeeper = require('./utils/window_state');
var windowMenu = require('./utils/window_menu');
// set path env
process.env.ELECTRON_APP_DIR = app.getAppPath();
process.env.NODE_CONFIG_DIR = process.env.ELECTRON_APP_DIR + '/config';
var application = require('./app.coffee');
var mainWindow, webContents, instance;
// Preserver of the window size and position between app launches.
var mainWindowState = windowStateKeeper('main', {
width: 1000,
height: 600
});
instance = app.makeSingleInstance(function() {
if (mainWindow.isMinimized()){
mainWindow.restore()
}
mainWindow.focus();
return true;
});
app.on('ready', function () {
windowMenu.init();
mainWindow = new BrowserWindow({
minWidth: 768,
minHeight: 500,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height
});
webContents = mainWindow.webContents;
if (mainWindowState.isMaximized) {
mainWindow.maximize();
}
if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
}
mainWindow.on('close', function () {
mainWindowState.saveState(mainWindow);
});
// behavior for normal a hrefs
webContents.on("will-navigate", function (event, url) {
event.preventDefault();
if (url.match(/^http/)) shell.openExternal(url);
});
// behavior for '_blank' a hrefs
webContents.on('new-window', function(event, url){
event.preventDefault();
if (url.match(/^http/)) shell.openExternal(url);
});
process.on('uncaughtException', function(e) {
console.log('uncaught Exception:', e);
});
mainWindow.loadURL('file://' + __dirname + '/public/index.html');
// start Eintopf
application(webContents);
});
app.on('window-all-closed', function () {
require('./models/util/terminal.coffee').killPty(); // terminate lose pty instance
app.quit();
});
if (instance){
return app.quit();
}