-
-
Notifications
You must be signed in to change notification settings - Fork 37
Feature/shortcuts #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/shortcuts #153
Changes from all commits
e159d5f
bfcc2c6
c6d8d91
45a582a
4c648a3
ed7f839
9a490c2
177b7d1
c6ec180
e9c8a2e
1fb588e
861b658
afadd3f
1560f07
7c6cdde
9a58c11
88fe9a2
9908d4a
0fa99b1
530dbc6
a019c99
b051120
bd3cc3b
9231661
9759ed7
6432226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
global: { | ||
CONNECT: 'CommandOrControl+Shift+C', | ||
DISCONNECT: 'CommandOrControl+Shift+D', | ||
SAVE: 'CommandOrControl+S', | ||
RUN: 'CommandOrControl+R', | ||
RUN_SELECTION: 'CommandOrControl+Alt+R', | ||
RUN_SELECTION_WL: 'CommandOrControl+Alt+S', | ||
STOP: 'CommandOrControl+H', | ||
RESET: 'CommandOrControl+Shift+R', | ||
CLEAR_TERMINAL: 'CommandOrControl+L', | ||
EDITOR_VIEW: 'CommandOrControl+Alt+1', | ||
FILES_VIEW: 'CommandOrControl+Alt+2', | ||
ESC: 'Escape' | ||
}, | ||
menu: { | ||
CONNECT: 'CmdOrCtrl+Shift+C', | ||
DISCONNECT: 'CmdOrCtrl+Shift+D', | ||
SAVE: 'CmdOrCtrl+S', | ||
RUN: 'CmdOrCtrl+R', | ||
RUN_SELECTION: 'CmdOrCtrl+Alt+R', | ||
RUN_SELECTION_WL: 'CmdOrCtrl+Alt+S', | ||
STOP: 'CmdOrCtrl+H', | ||
RESET: 'CmdOrCtrl+Shift+R', | ||
CLEAR_TERMINAL: 'CmdOrCtrl+L', | ||
EDITOR_VIEW: 'CmdOrCtrl+Alt+1', | ||
FILES_VIEW: 'CmdOrCtrl+Alt+2' | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||
const { app, BrowserWindow, ipcMain, dialog } = require('electron') | ||||
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') | ||||
|
@@ -49,12 +50,59 @@ function createWindow () { | |||
win.show() | ||||
}) | ||||
|
||||
win.webContents.on('before-reload', async (event) => { | ||||
// Prevent the default reload behavior | ||||
event.preventDefault() | ||||
|
||||
try { | ||||
// Tell renderer to do cleanup | ||||
win.webContents.send('cleanup-before-reload') | ||||
|
||||
// Wait for cleanup then reload | ||||
setTimeout(() => { | ||||
// This will trigger a page reload, but won't trigger 'before-reload' again | ||||
win.reload() | ||||
}, 500) | ||||
} catch(e) { | ||||
console.error('Reload preparation failed:', e) | ||||
} | ||||
}) | ||||
Comment on lines
+53
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this when merging #158 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you'll have to do this in your PR :) |
||||
|
||||
const initialMenuState = { | ||||
isConnected: false, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Superfluous if isConnected is not set it has a falsy value
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually at first menu registration you want to hide Run, Stop etc based on an initial state, forced to be |
||||
view: 'editor' | ||||
} | ||||
|
||||
registerIPCHandlers(win, ipcMain, app, dialog) | ||||
registerMenu(win) | ||||
registerMenu(win, initialMenuState) | ||||
|
||||
app.on('activate', () => { | ||||
if (BrowserWindow.getAllWindows().length === 0) createWindow() | ||||
}) | ||||
} | ||||
|
||||
app.on('ready', 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() | ||||
}) | ||||
ubidefeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
console.log('preload') | ||
const { contextBridge, ipcRenderer } = require('electron') | ||
const path = require('path') | ||
|
||
const shortcuts = require('./backend/shortcuts.js').global | ||
const MicroPython = require('micropython.js') | ||
const { emit, platform } = require('process') | ||
|
||
const board = new MicroPython() | ||
board.chunk_size = 192 | ||
board.chunk_sleep = 200 | ||
|
@@ -155,12 +157,37 @@ const Window = { | |
setWindowSize: (minWidth, minHeight) => { | ||
ipcRenderer.invoke('set-window-size', minWidth, minHeight) | ||
}, | ||
onKeyboardShortcut: (callback, key) => { | ||
ipcRenderer.on('shortcut-cmd', (event, k) => { | ||
callback(k); | ||
}) | ||
}, | ||
|
||
onBeforeReload: (callback) => { | ||
ipcRenderer.on('cleanup-before-reload', async () => { | ||
try { | ||
await callback() | ||
} catch(e) { | ||
console.error('Cleanup before reload failed:', e) | ||
} | ||
}) | ||
}, | ||
Comment on lines
+166
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to go when merging #158 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sebromero , could you take it out when you rebase #158 after this is merged? |
||
|
||
beforeClose: (callback) => ipcRenderer.on('check-before-close', callback), | ||
confirmClose: () => ipcRenderer.invoke('confirm-close'), | ||
isPackaged: () => ipcRenderer.invoke('is-packaged'), | ||
openDialog: (opt) => ipcRenderer.invoke('open-dialog', opt) | ||
} | ||
openDialog: (opt) => ipcRenderer.invoke('open-dialog', opt), | ||
|
||
getOS: () => platform, | ||
isWindows: () => platform === 'win32', | ||
isMac: () => platform === 'darwin', | ||
isLinux: () => platform === 'linux', | ||
|
||
updateMenuState: (state) => { | ||
return ipcRenderer.invoke('update-menu-state', state) | ||
}, | ||
getShortcuts: () => shortcuts | ||
} | ||
|
||
contextBridge.exposeInMainWorld('BridgeSerial', Serial) | ||
contextBridge.exposeInMainWorld('BridgeDisk', Disk) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to go when we merge #158