-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.js
92 lines (76 loc) · 2.64 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
const { app, BrowserWindow, ipcMain, nativeTheme } = require('electron');
const StoreManager = require('./assets/js/store.js');
const MenuManager = require('./assets/js/menu.js');
const UpdateManager = require('./assets/js/update.js');
const appIcon = './assets/icons/png/64x64.png';
const menuManager = new MenuManager();
const updateManager = new UpdateManager();
const storeManager = new StoreManager({
configName: 'preferences',
defaults: {
windowBounds: {
width: 1000,
height: 800,
x: undefined,
y: undefined,
maximized: false
},
darkMode: false,
},
});
let mainWindow;
function createWindow() {
// get data from store
let { width, height, x, y, maximized } = storeManager.get('windowBounds');
mainWindow = new BrowserWindow({
x, y,
width, height,
maximized,
icon: appIcon,
minWidth: 700,
minHeight: 740,
webPreferences: {
enableRemoteModule: true,
contextIsolation: false,
nodeIntegration: true
}});
mainWindow.loadFile('index.html');
// check if we need to maximize main window
maximized && mainWindow.maximize();
// set main window
storeManager.setWindow(mainWindow);
menuManager.setWindow(mainWindow);
updateManager.setWindow(mainWindow);
// set window bounds events
storeManager.setEvents();
// build menu
menuManager.buildMenu();
// check for update
updateManager.checkForUpdate();
// show dev tools on start
// mainWindow.webContents.openDevTools();
ipcMain.on('toggle-dark-mode', function () {
if (nativeTheme.shouldUseDarkColors) {
nativeTheme.themeSource = 'light'
storeManager.set('darkMode', false);
} else {
nativeTheme.themeSource = 'dark'
storeManager.set('darkMode', true);
}
return nativeTheme.shouldUseDarkColors
});
mainWindow.webContents.on('did-finish-load', () => {
// set app theme on load
const appDarkMode = storeManager.get('darkMode');
if (appDarkMode) {
mainWindow.webContents.send('set-dark-mode');
nativeTheme.themeSource = 'dark';
} else {
nativeTheme.themeSource = 'light';
}
});
mainWindow.on('closed', function() { mainWindow = null });
}
app.whenReady().then(createWindow);
app.on('window-all-closed', function() { if (process.platform !== 'darwin') { app.quit(); } });
app.on('activate', function() { if (mainWindow === null) { createWindow(); } });