-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
133 lines (115 loc) · 3.39 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var electron = require('electron')
const { BrowserWindow } = require('electron/main')
const path = require('path');
const { fstat } = require('original-fs')
const fs = require("fs");
const browserWindow = electron.BrowserWindow // use window
var app = electron.app // use app
const configJson = path.join(__dirname, "config/config.json").replace(/\\/g, "\/");
var mainWindow = null // the main window
var result = null;
var timeJson = null, textJson = null;
// fs.exists(configJson, function (exists) {
// console.log(exists ? "文件存在" : "文件不存在");
// if (!exists) {
// $(".errorInformation").show();
// $(".errorInformation").text("查找失败,文件不存在!");
// return;
// } else {
//
// //读取本地的json文件
// console.log(JSON.parse(fs.readFileSync(configJson)));
// console.log('here');
// }
// });
result = JSON.parse(fs.readFileSync(configJson));
if (result != null && result != '') {
for (var key in result) {
if (key === 'timeJsonPath') {
timeJson = result[key];
}
else if (key === 'textJsonPath') {
textJson = result[key];
}
}
} else {
console.log('NullResult');
}
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 500, height: 500,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
}
});
// load page
if (process.argv.length != 2) {
var choose = process.argv[2];
switch (choose) {
case '0':
mainWindow = new BrowserWindow({
fullscreen: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
}
})
mainWindow.loadFile('pages/clock/clock.html')
var h = process.argv[3]
var m = process.argv[4]
var s = process.argv[5]
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('h', h)
mainWindow.webContents.send('m', m)
mainWindow.webContents.send('s', s)
})
break;
case '1':
mainWindow.loadFile('pages/input/index.html')
break;
case '2':
mainWindow = new BrowserWindow({
fullscreen: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
}
})
mainWindow.loadFile('pages/clock/clock.html')
var h = null, m = null, s = null;
result = JSON.parse(fs.readFileSync(timeJson))
if (result != null && result != '') {
for (var key in result) {
if (key === 'hh') {
h = result[key];
} else if (key === 'mm') {
m = result[key];
} else if (key === 'ss') {
s = result[key];
}
}
} else {
console.log('NullTimeJson');
}
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('txt', textJson)
mainWindow.webContents.send('h', h)
mainWindow.webContents.send('m', m)
mainWindow.webContents.send('s', s)
})
break;
default:
console.log("ErrorNumber");
break;
}
} else {
mainWindow.loadFile('pages/input/index.html')
}
mainWindow.on('close', () => {
mainWindow = null
})
})