-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
120 lines (106 loc) · 2.86 KB
/
app.js
File metadata and controls
120 lines (106 loc) · 2.86 KB
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
const
package = require('./package.json'),
fs = require('fs'),
path = require('path'),
electron = require('electron');
const databasePath = path.join(electron.app.getPath('appData'), package.name, '.database.json');
async function readDatabase() {
if(await fs.existsSync(databasePath) == true) {
try {
let data = await fs.readFileSync(databasePath);
if(data == null) return null;
else {
data = await JSON.parse(data);
return data.length == 0? null: data;
}
} catch (error) {
return null;
}
} else {
await fs.writeFileSync(databasePath, '[]');
return null;
}
}
function createWelcomeWindow() {
let win = new electron.BrowserWindow({
width: 600,
height: 350,
resizable: false,
maximizable: false,
fullscreen: false,
show: false,
webPreferences: {
nodeIntegration: true
}
});
win.center();
win.removeMenu();
win.loadURL(path.join(__dirname, 'windows', 'welcome', 'template.html'));
win.on('ready-to-show', ()=>{
win.show();
});
}
function createEventWindow(index=0, size=200) {
let win = new electron.BrowserWindow({
minWidth: 100,
minHeight: 100,
width: size,
height: size,
frame: false,
fullscreen: false,
transparent: true,
fullscreenable: false,
alwaysOnTop: true,
maximizable: false,
webPreferences: {
nodeIntegration: true
}
});
win.center();
win.removeMenu();
win.loadURL(path.join(__dirname, 'windows', 'main', `template.html?index=${index}`));
win.on('ready-to-show', ()=>{
win.show();
});
}
function createHelpWindow(win) {
let help = new electron.BrowserWindow({
width: 300,
height: 310,
fullscreen: false,
fullscreenable: false,
alwaysOnTop: true,
maximizable: false,
parent: win,
webPreferences: {
nodeIntegration: true
}
});
help.center();
help.removeMenu();
help.loadURL(path.join(__dirname, 'windows', 'help', 'template.html'));
}
electron.app.whenReady()
.then(readDatabase)
.then(data=>{
if(data == null) createWelcomeWindow();
else {
let count = 0;
for(let i in data) {
if(
(data[i]['disabled'] && data[i]['disabled'] == true) ||
(data[i]['hide'] && data[i]['hide'] == true)
) {
continue;
} else {
createEventWindow(i, data[i]['size']);
count++;
}
}
if(count == 0) createWelcomeWindow();
}
});
electron.ipcMain.on('f1', (event, win)=>{
createHelpWindow(win);
event.returnValue = '';
});