-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_tool.js
69 lines (56 loc) · 1.9 KB
/
config_tool.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
const {app, BrowserWindow, ipcMain, systemPreferences} = require('electron');
const path = require('path');
const url = require('url');
const isDev = require('electron-is-dev');
const monitorinfo = require('./monitorinfo.js');
const DataStore = require('./datastore.js');
const {simpleClone} = require('./utils.js');
var exports = module.exports = {};
var win;
exports.createWindow = function() {
win = new BrowserWindow({
width: 800,
height: 600,
minWidth: 513,
minHeight: 374,
icon: path.join(__dirname, 'static', 'res', 'icon.png')
});
win.loadURL(url.format({
pathname: path.join(__dirname, 'static', 'index.html'),
protocol: 'file:',
slashes: true
}));
win.setMenu(null);
if(isDev) {
win.webContents.openDevTools();
}
win.on('closed', function() {
win = null;
});
ipcMain.on('query-accent-color', () => {
win.send('accent-color', systemPreferences.getAccentColor());
});
systemPreferences.on('accent-color-changed', (_, new_color) => {
win.send('accent-color', new_color);
});
ipcMain.on('query-monitors', () => {
monitorinfo.load().then(monitors => {
win.send('monitors', simpleClone(monitors));
}).catch(() => {});
});
monitorinfo.on('change', (new_monitors) => {
win.send('monitors', simpleClone(new_monitors));
});
var profiles_store = new DataStore('config.json');
ipcMain.on('query-profiles', () => {
profiles_store.load((_, profiles) => {
win.send('profiles', simpleClone(profiles));
});
});
ipcMain.on('save-profiles', (_, profiles) => {
profiles_store.save(profiles);
});
profiles_store.on('change', (new_profiles) => {
win.send('profiles', simpleClone(new_profiles));
});
};