-
-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathstart-debug.js
77 lines (66 loc) · 1.72 KB
/
start-debug.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 electron = require('electron');
const app = electron.app;
const fs = require('fs');
const path = require('path');
const Promise = require('promise');
//require('electron-debugger')();
let mainWindow;
function onClosed() {
// dereference the window
// for multiple windows store them in an array
mainWindow = null;
}
function createTempHtml() {
return new Promise((resolve, reject) => {
let newFile = __dirname+'/app/tmp.index.html';
let subRegexs = [
{ regex: /(bower_components)/g, value: "../$1" },
{ regex: /(styles\/main.css)/g, value: "../.tmp/$1" }
];
fs.readFile(__dirname+'/app/index.html', 'utf8', (err,data) => {
if (err) {
reject(err);
}
for (let reg of subRegexs) {
data = data.replace(reg.regex, reg.value);
}
console.log(data);
fs.writeFile(newFile, data, (err) => {
if (err) {
reject(err);
}
resolve(newFile)
});
});
});
}
function createMainWindow(width, height) {
const win = new electron.BrowserWindow({
width: width,
height: height,
icon: path.join(__dirname, 'app/images/icons/512.ico')
});
let tempHtmlFile = createTempHtml();
tempHtmlFile.then((data) => {
win.loadURL('file://'+data);
}).catch((err) => {
console.log(err);
})
win.on('closed', onClosed);
return win;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
/*if (!mainWindow) {
mainWindow = createMainWindow();
}*/
});
app.on('ready', () => {
const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize;
mainWindow = createMainWindow(width, height);
});