-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
86 lines (71 loc) · 2.08 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
const { app, screen, Tray, globalShortcut, BrowserWindow } = require('electron')
const ioHook = require('iohook')
const path = require('path')
const keyCodes = require('./keys')
const { changeImg, toggleWindow } = require('./utils')
const iconPath = path.join(__dirname, 'images/[email protected]')
let mainWindow
let trays
app.on('ready', createWindow)
app.on('window-all-closed', function() {
ioHook.unregisterAllShortcuts()
globalShortcut.unregisterAll()
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function() {
if (mainWindow === null) createWindow()
})
function createWindow() {
let display = screen.getPrimaryDisplay()
let height = display.bounds.height
trays = new Tray(iconPath)
mainWindow = new BrowserWindow({
width: 500,
height: 190,
x: 0,
y: height,
frame: false,
transparent: true
})
mainWindow.setIgnoreMouseEvents(true)
ioHook.on('keydown', event => {
trays.setTitle(keyCodes[event.rawcode] || '' + '')
})
// If you want to show something like 'CMD + C' (Copy)
// ioHook.registerShortcut([3675, 42], (keys) => {
// trays.setTitle(`${keyCodes[55]} + ${keyCodes[56] }` || null)
// console.log('Shortcut called with keys:', keys)
// });
globalShortcut.register('Command+)', () => {
toggleWindow(mainWindow)
})
globalShortcut.register('Command+1', () => {
if (mainWindow.isVisible()) {
changeImg('1', mainWindow)
}
})
globalShortcut.register('Command+2', () => {
if (mainWindow.isVisible()) {
changeImg('2', mainWindow)
}
})
globalShortcut.register('Command+3', () => {
if (mainWindow.isVisible()) {
changeImg('3', mainWindow)
}
})
globalShortcut.register('Command+4', () => {
if (mainWindow.isVisible()) {
changeImg('4', mainWindow)
}
})
ioHook.start()
mainWindow.setAlwaysOnTop(true, 'floating')
mainWindow.setVisibleOnAllWorkspaces(true)
mainWindow.loadURL(`file://${__dirname}/html/index.html`)
// Open the DevTools.---
// mainWindow.webContents.openDevTools()
mainWindow.on('closed', function() {
mainWindow = null
})
}