Skip to content

Commit 177b7d1

Browse files
committed
Implemented Board menu item.
Signed-off-by: ubi de feo <[email protected]>
1 parent 9a490c2 commit 177b7d1

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

backend/ipc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ module.exports = function registerIPCHandlers(win, ipcMain, app, dialog) {
129129
return response != opt.cancelId
130130
})
131131

132+
ipcMain.handle('update-menu-state', (event, state) => {
133+
const registerMenu = require('./menu.js')
134+
registerMenu(win, state)
135+
})
136+
132137
win.on('close', (event) => {
133138
console.log('BrowserWindow', 'close')
134139
event.preventDefault()

backend/menu.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { app, Menu } = require('electron')
22
const path = require('path')
33
const openAboutWindow = require('about-window').default
44

5-
module.exports = function registerMenu(win) {
5+
module.exports = function registerMenu(win, state = {}) {
66
const isMac = process.platform === 'darwin'
77
const template = [
88
...(isMac ? [{
@@ -11,7 +11,7 @@ module.exports = function registerMenu(win) {
1111
{ role: 'about'},
1212
{ type: 'separator' },
1313
{ type: 'separator' },
14-
{ role: 'hide' },
14+
{ role: 'hide', accelerator: 'CmdOrCtrl+Shift+H' },
1515
{ role: 'hideOthers' },
1616
{ role: 'unhide' },
1717
{ type: 'separator' },
@@ -50,6 +50,40 @@ module.exports = function registerMenu(win) {
5050
])
5151
]
5252
},
53+
{
54+
label: 'Board',
55+
submenu: [
56+
{
57+
label: 'Connect',
58+
accelerator: 'CmdOrCtrl+Shift+C',
59+
click: () => win.webContents.send('shortcut-cmd', 'C')
60+
},
61+
{
62+
label: 'Disconnect',
63+
accelerator: 'CmdOrCtrl+Shift+D',
64+
click: () => win.webContents.send('shortcut-cmd', 'D')
65+
},
66+
{ role: 'separator' },
67+
{
68+
label: 'Run',
69+
accelerator: 'CmdOrCtrl+R',
70+
enabled: state.isConnected && state.view === 'editor',
71+
click: () => win.webContents.send('shortcut-cmd', 'r')
72+
},
73+
{
74+
label: 'Stop',
75+
accelerator: 'CmdOrCtrl+H',
76+
enabled: state.isConnected && state.view === 'editor',
77+
click: () => win.webContents.send('shortcut-cmd', 'h')
78+
},
79+
{
80+
label: 'Reset',
81+
accelerator: 'CmdOrCtrl+Shift+R',
82+
enabled: state.isConnected && state.view === 'editor',
83+
click: () => win.webContents.send('shortcut-cmd', 'R')
84+
}
85+
]
86+
},
5387
{
5488
label: 'View',
5589
submenu: [

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ function createWindow () {
4949
win.show()
5050
})
5151

52+
const initialMenuState = {
53+
isConnected: false,
54+
view: 'editor'
55+
}
56+
5257
registerIPCHandlers(win, ipcMain, app, dialog)
53-
registerMenu(win)
58+
registerMenu(win, initialMenuState)
5459

5560
app.on('activate', () => {
5661
if (BrowserWindow.getAllWindows().length === 0) createWindow()

preload.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ const Window = {
180180
getOS: () => platform,
181181
isWindows: () => platform === 'win32',
182182
isMac: () => platform === 'darwin',
183-
isLinux: () => platform === 'linux'
183+
isLinux: () => platform === 'linux',
184+
185+
updateMenuState: (state) => {
186+
return ipcRenderer.invoke('update-menu-state', state)
187+
}
188+
184189
}
185190

186191
contextBridge.exposeInMainWorld('BridgeSerial', Serial)

ui/arduino/store.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ async function store(state, emitter) {
8181
emitter.emit('render')
8282
}
8383

84+
// Menu management
85+
const updateMenu = () => {
86+
window.BridgeWindow.updateMenuState({
87+
isConnected: state.isConnected,
88+
view: state.view
89+
})
90+
}
91+
8492
// START AND BASIC ROUTING
8593
emitter.on('select-disk-navigation-root', async () => {
8694
const folder = await selectDiskFolder()
@@ -98,6 +106,7 @@ async function store(state, emitter) {
98106
emitter.emit('refresh-files')
99107
}
100108
emitter.emit('render')
109+
updateMenu()
101110
})
102111

103112
// CONNECTION DIALOG
@@ -143,11 +152,13 @@ async function store(state, emitter) {
143152
}
144153
// Stop whatever is going on
145154
// Recover from getting stuck in raw repl
155+
146156
await serial.getPrompt()
147157
clearTimeout(timeout_id)
148158
// Connected and ready
149159
state.isConnecting = false
150160
state.isConnected = true
161+
updateMenu()
151162
if (state.view === 'editor' && state.panelHeight <= PANEL_CLOSED) {
152163
state.panelHeight = state.savedPanelHeight
153164
}
@@ -181,6 +192,7 @@ async function store(state, emitter) {
181192
state.boardNavigationPath = '/'
182193
emitter.emit('refresh-files')
183194
emitter.emit('render')
195+
updateMenu()
184196
})
185197
emitter.on('connection-timeout', async () => {
186198
state.isConnected = false
@@ -1646,4 +1658,5 @@ async function getHelperFullPath() {
16461658
''
16471659
)
16481660
}
1661+
16491662
}

0 commit comments

Comments
 (0)