/
main.js
77 lines (62 loc) · 1.7 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
'use strict';
const path = require('path');
const glob = require('glob')
const electron = require('electron');
const app = electron.app;
const config = require('./lib/config');
// jade stuff
const locals = {};
const jade = require('./lib/electron-jade')({pretty: true}, locals);
require('dotenv').load();
var mainWindow = null;
let mainWindowBounds;
let isQuitting = false;
load_main_proc()
function createMainWindow() {
const lastWindowState = config.get('lastWindowState');
const win = new electron.BrowserWindow({
show: false,
x: lastWindowState.x,
y: lastWindowState.y,
width: lastWindowState.width,
height: lastWindowState.height,
minWidth: 1020,
minHeight: 795,
titleBarStyle: 'hidden-inset',
autoHideMenuBar: true
});
// NOTE: the URL is enclosed in backticks NOT single quotes
win.loadURL(`file://${__dirname}/index.jade`);
return win;
}
app.on('ready', function() {
mainWindow = createMainWindow();
const page = mainWindow.webContents;
page.on('dom-ready', function() {
mainWindow.show();
});
mainWindow.on('close', function() {
mainWindowBounds = mainWindow.getBounds();
});
});
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
// console.log(mainWindowBounds);
});
app.on('before-quit', function() {
isQuitting = true;
config.set('lastWindowState', {
width: mainWindowBounds.width,
height: mainWindowBounds.height,
x: mainWindowBounds.x,
y: mainWindowBounds.y
});
});
// Require each JS file in the main-process dir
function load_main_proc () {
var files = glob.sync(path.join(__dirname, 'main-process/**/*.js'))
files.forEach(function (file) {
require(file)
})
}