Skip to content

Commit cc93603

Browse files
committed
Merge branch 'bugfix/about-window-issues' into feature/new-toolbar
2 parents c996824 + fa82c79 commit cc93603

File tree

5 files changed

+90
-55
lines changed

5 files changed

+90
-55
lines changed

backend/menu.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
const { app, Menu } = require('electron')
2+
const { shortcuts, disableShortcuts } = require('./shortcuts.js')
23
const path = require('path')
34
const serial = require('./serial/serial.js').sharedInstance
45
const openAboutWindow = require('about-window').default
5-
const shortcuts = require('./shortcuts.js')
6+
67
const { type } = require('os')
78

9+
let appInfoWindow = null
10+
11+
function closeAppInfo(win) {
12+
disableShortcuts(win, false)
13+
appInfoWindow.off('close', () => closeAppInfo(win))
14+
appInfoWindow = null
15+
16+
}
17+
function openAppInfo(win) {
18+
if (appInfoWindow != null) {
19+
appInfoWindow.show()
20+
} else {
21+
appInfoWindow = openAboutWindow({
22+
icon_path: path.resolve(__dirname, '../ui/arduino/media/about_image.png'),
23+
css_path: path.resolve(__dirname, '../ui/arduino/views/about.css'),
24+
copyright: '© Arduino SA 2022',
25+
package_json_dir: path.resolve(__dirname, '..'),
26+
bug_report_url: "https://github.com/arduino/lab-micropython-editor/issues",
27+
bug_link_text: "report an issue",
28+
homepage: "https://labs.arduino.cc",
29+
use_version_info: false,
30+
win_options: {
31+
parent: win,
32+
modal: true,
33+
},
34+
show_close_button: 'Close',
35+
})
36+
appInfoWindow.on('close', () => closeAppInfo(win));
37+
disableShortcuts(win, true)
38+
}
39+
}
40+
841
module.exports = function registerMenu(win, state = {}) {
942
const isMac = process.platform === 'darwin'
1043
const template = [
@@ -22,6 +55,10 @@ module.exports = function registerMenu(win, state = {}) {
2255
{
2356
label: 'File',
2457
submenu: [
58+
{ label: 'Save',
59+
accelerator: shortcuts.menu.SAVE,
60+
click: () => win.webContents.send('shortcut-cmd', shortcuts.global.SAVE)
61+
},
2562
isMac ? { role: 'close' } : { role: 'quit' }
2663
]
2764
},
@@ -166,40 +203,14 @@ module.exports = function registerMenu(win, state = {}) {
166203
},
167204
{
168205
label:'About Arduino Lab for MicroPython',
169-
click: () => {
170-
openAboutWindow({
171-
icon_path: path.resolve(__dirname, '../ui/arduino/media/about_image.png'),
172-
css_path: path.resolve(__dirname, '../ui/arduino/views/about.css'),
173-
copyright: '© Arduino SA 2022',
174-
package_json_dir: path.resolve(__dirname, '..'),
175-
bug_report_url: "https://github.com/arduino/lab-micropython-editor/issues",
176-
bug_link_text: "report an issue",
177-
homepage: "https://labs.arduino.cc",
178-
use_version_info: false,
179-
win_options: {
180-
parent: win,
181-
modal: true,
182-
},
183-
show_close_button: 'Close',
184-
})
185-
}
206+
click: () => { openAppInfo(win) }
186207
},
187208
]
188209
}
189210
]
190211

191212
const menu = Menu.buildFromTemplate(template)
192213

193-
app.setAboutPanelOptions({
194-
applicationName: app.name,
195-
applicationVersion: app.getVersion(),
196-
copyright: app.copyright,
197-
credits: '(See "Info about this app" in the Help menu)',
198-
authors: ['Arduino'],
199-
website: 'https://arduino.cc',
200-
iconPath: path.join(__dirname, '../assets/image.png'),
201-
})
202-
203214
Menu.setApplicationMenu(menu)
204215

205216
}

backend/shortcuts.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
module.exports = {
1+
const { globalShortcut } = require('electron')
2+
let shortcutsActive = false
3+
const shortcuts = {
24
global: {
35
CONNECT: 'CommandOrControl+Shift+C',
46
DISCONNECT: 'CommandOrControl+Shift+D',
@@ -26,5 +28,32 @@ module.exports = {
2628
CLEAR_TERMINAL: 'CmdOrCtrl+L',
2729
EDITOR_VIEW: 'CmdOrCtrl+Alt+1',
2830
FILES_VIEW: 'CmdOrCtrl+Alt+2'
29-
}
31+
},
32+
// Shortcuts
33+
}
34+
35+
function shortcutAction(key, win) {
36+
console.log("key:", key)
37+
win.send('shortcut-cmd', key);
38+
}
39+
40+
function registerShortcuts (win) {
41+
console.log("registering shortcuts")
42+
win.send('ignore-shortcuts', false)
43+
}
44+
function unregisterShortcuts(win) {
45+
console.log("unregistering shortcuts")
46+
// globalShortcut.unregisterAll()
47+
win.send('ignore-shortcuts', true)
48+
}
49+
50+
function disableShortcuts (win, value) {
51+
console.log("registering shortcuts")
52+
win.send('ignore-shortcuts', value)
53+
}
54+
55+
module.exports = {
56+
shortcuts,
57+
disableShortcuts
3058
}
59+

index.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const { app, BrowserWindow, ipcMain, dialog, globalShortcut } = require('electron')
22
const path = require('path')
33
const fs = require('fs')
4-
const shortcuts = require('./backend/shortcuts.js').global
5-
64
const registerIPCHandlers = require('./backend/ipc.js')
75
const registerMenu = require('./backend/menu.js')
86

@@ -63,28 +61,15 @@ function createWindow () {
6361
})
6462
}
6563

66-
function shortcutAction(key) {
67-
win.webContents.send('shortcut-cmd', key);
68-
}
69-
70-
// Shortcuts
71-
function registerShortcuts() {
72-
Object.entries(shortcuts).forEach(([command, shortcut]) => {
73-
globalShortcut.register(shortcut, () => {
74-
shortcutAction(shortcut)
75-
});
76-
})
77-
}
78-
7964
app.on('ready', () => {
8065
createWindow()
81-
registerShortcuts()
8266

8367
win.on('focus', () => {
84-
registerShortcuts()
68+
console.log("win focus")
8569
})
70+
8671
win.on('blur', () => {
87-
globalShortcut.unregisterAll()
72+
console.log("win blur")
8873
})
8974

90-
})
75+
})

preload.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
console.log('preload')
22
const { contextBridge, ipcRenderer } = require('electron')
33
const path = require('path')
4-
const shortcuts = require('./backend/shortcuts.js').global
4+
const shortcuts = require('./backend/shortcuts.js').shortcuts.global
55
const { emit, platform } = require('process')
66
const SerialBridge = require('./backend/serial/serial-bridge.js')
77

@@ -63,6 +63,12 @@ const Window = {
6363
callback(k);
6464
})
6565
},
66+
onDisableShortcuts: (callback, value) => {
67+
ipcRenderer.on('ignore-shortcuts', (e, value) => {
68+
console.log("ipcRenderer ignore-shortcuts", value)
69+
callback(value);
70+
})
71+
},
6672

6773
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback),
6874
confirmClose: () => ipcRenderer.invoke('confirm-close'),

ui/arduino/store.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ async function store(state, emitter) {
6767

6868
state.isTerminalBound = false
6969

70+
state.shortcutsDisabled = false
71+
7072
await createNewTab('disk')
7173
state.savedPanelHeight = PANEL_DEFAULT
7274
state.panelHeight = PANEL_CLOSED
@@ -1418,12 +1420,14 @@ async function store(state, emitter) {
14181420
await win.confirmClose()
14191421
})
14201422

1421-
// win.shortcutCmdR(() => {
1422-
// // Only run if we can execute
1423-
1424-
// })
1425-
1423+
win.onDisableShortcuts((disable) => {
1424+
console.log('state.shortcutsDisabled', disable)
1425+
state.shortcutsDisabled = disable
1426+
}),
1427+
14261428
win.onKeyboardShortcut((key) => {
1429+
if (state.shortcutsDisabled) return
1430+
14271431
if (key === shortcuts.CONNECT) {
14281432
emitter.emit('open-connection-dialog')
14291433
}

0 commit comments

Comments
 (0)