-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (61 loc) · 1.89 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
'use strict';
var app = require('app');
var BrowserWindow = require('browser-window');
var globalShortcut = require('global-shortcut');
var configuration = require('./configuration');
var ipc = require('ipc');
var mainWindow = null;
var settingsWindow = null;
app.on('ready', function() {
if (!configuration.readSettings('shortcutKeys')) {
configuration.saveSettings('shortcutKeys', ['ctrl', 'shift']);
}
mainWindow = new BrowserWindow({
frame: false,
height: 700,
resizable: false,
width: 368
});
//mainWindow.loadUrl('file://' + __dirname + '/app/index.html');
mainWindow.loadUrl('file://' + __dirname + '/app/test.html');
setGlobalShortcuts();
});
function setGlobalShortcuts() {
globalShortcut.unregisterAll();
var shortcutKeysSetting = configuration.readSettings('shortcutKeys');
var shortcutPrefix = shortcutKeysSetting.length === 0 ? '' : shortcutKeysSetting.join('+') + '+';
globalShortcut.register(shortcutPrefix + '1', function () {
mainWindow.webContents.send('global-shortcut', 0);
});
globalShortcut.register(shortcutPrefix + '2', function () {
mainWindow.webContents.send('global-shortcut', 1);
});
}
ipc.on('close-main-window', function () {
app.quit();
});
//设置的小窗口
ipc.on('open-settings-window', function () {
if (settingsWindow) {
return;
}
settingsWindow = new BrowserWindow({
frame: false,
height: 200,
resizable: false,
width: 200
});
settingsWindow.loadUrl('file://' + __dirname + '/app/settings.html');
settingsWindow.on('closed', function () {
settingsWindow = null;
});
});
//关闭小窗口-----------------
ipc.on('close-settings-window', function () {
if (settingsWindow) {
settingsWindow.close();
}
});
ipc.on('set-global-shortcuts', function () {
setGlobalShortcuts();
});