-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
146 lines (95 loc) · 2.95 KB
/
index.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
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Main Process JavaScript */
/* eslint-disable no-console */
const electron = require('electron');
const os = require('os');
const { app, BrowserWindow, ipcMain, dialog } = electron;
console.log('running index.js');
console.log(`Host Device: '${os.hostname()}'`);
const developerHosts = [ 'BRAYDENS-LENOVO' ]; // List of developer host devices
const inDebugMode = developerHosts.includes(os.hostname());
let indexOpenDialogTime = 0;
let indexSaveDialogTime = 0;
ipcMain.on('open-dialog', (event, options) => {
if (indexOpenDialogTime && Date.now() - indexOpenDialogTime < 1000)
return;
indexOpenDialogTime = Date.now();
console.log('Showing File Open Dialog.');
dialog.showOpenDialog(options, (filename) => {
event.sender.send('opened-file', filename);
});
});
ipcMain.on('save-dialog', (event, options) => {
if (indexSaveDialogTime && Date.now() - indexSaveDialogTime < 1000)
return;
indexSaveDialogTime = Date.now();
console.log('Showing File Save Dialog.');
dialog.showSaveDialog(options, (filename) => {
event.sender.send('saved-file', filename);
});
});
app.on('browser-window-created', (e, window) => {
window.setMenu(null);
});
app.on('ready', () => {
let win = null;
if (inDebugMode) { // If running this on braydens laptop, open it in development mode
console.log('Opening in development mode.');
console.log('electron', electron);
win = new BrowserWindow({
// show: false,
// width: 980,
// height: 620,
width: 1180,
height: 880,
// fullscreen: true,
// kiosk: true,
frame: true,
// backgroundColor: '#eaedf4',
backgroundThrottling: false,
// webPreferences: {
// nodeIntegration: false
// }
icon: `${__dirname}/icons/icon.ico`
});
} else { // If not running on braydens laptop, open the program in deployment mode
console.log('Opening in deployment mode.');
win = new BrowserWindow({
// show: false,
// width: 1650,
// height: 950,
// fullscreen: true,
// kiosk: true,
width: 1180,
height: 880,
frame: true,
// backgroundColor: '#eaedf4',
backgroundThrottling: false,
// webPreferences: {
// nodeIntegration: false
// }
icon: `${__dirname}/icons/icon.ico`
});
}
win.loadURL(`file://${__dirname}/main.html`);
if (os.hostname() === 'BRAYDENS-LENOVO')
win.webContents.openDevTools();
win.webContents.on('did-finish-load', () => {
console.log('Got \'did-finish-load\' event.');
});
ipcMain.on('all-widgets-loaded', () => { // Called after all widgets initBody() functions and after initial visibility has been set and sidebar buttons have been created
win.show();
win.focus();
console.log('Got ipcMain event: \'all-widgets-loaded\'.\n ...showing window.');
});
ipcMain.on('open-dev-tools', () => {
win.webContents.openDevTools();
win.focus();
console.log('Got ipcMain event: \'open-dev-tools\'.');
});
ipcMain.on('focus-window', () => {
win.focus();
});
win.on('close', () => {
win = null;
});
});