-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.js
90 lines (77 loc) · 1.98 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
const { app, BrowserWindow, ipcMain, dialog, globalShortcut } = require('electron')
const path = require('path')
const fs = require('fs')
const shortcuts = require('./backend/shortcuts.js').global
const registerIPCHandlers = require('./backend/ipc.js')
const registerMenu = require('./backend/menu.js')
let win = null // main window
let splash = null
let splashTimestamp = null
// START APP
function createWindow () {
// Create the browser window.
win = new BrowserWindow({
width: 720,
height: 640,
webPreferences: {
nodeIntegration: false,
webSecurity: true,
enableRemoteModule: false,
preload: path.join(__dirname, "preload.js"),
show: false
}
})
// and load the index.html of the app.
win.loadFile('ui/arduino/index.html')
// If the app takes a while to open, show splash screen
// Create the splash screen
splash = new BrowserWindow({
width: 450,
height: 140,
transparent: true,
frame: false,
alwaysOnTop: true
});
splash.loadFile('ui/arduino/splash.html')
splashTimestamp = Date.now()
win.once('ready-to-show', () => {
if (Date.now()-splashTimestamp > 1000) {
splash.destroy()
} else {
setTimeout(() => {
splash.destroy()
}, 500)
}
win.show()
})
const initialMenuState = {
isConnected: false,
view: 'editor'
}
registerIPCHandlers(win, ipcMain, app, dialog)
registerMenu(win, initialMenuState)
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
}
function shortcutAction(key) {
win.webContents.send('shortcut-cmd', key);
}
// Shortcuts
function registerShortcuts() {
Object.entries(shortcuts).forEach(([command, shortcut]) => {
globalShortcut.register(shortcut, () => {
shortcutAction(shortcut)
});
})
}
app.on('ready', () => {
createWindow()
registerShortcuts()
win.on('focus', () => {
registerShortcuts()
})
win.on('blur', () => {
globalShortcut.unregisterAll()
})
})