Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

use local shortcuts for dev tools and plugins #500

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions js/rendererjs/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ const createPluginElement = (markupPath, title) => {
return elem
}

// registerLocalShortcut registers an electron globalShortcut that is only
// active when the app has focus.
const registerLocalShortcut = (shortcut, action) => {
remote.app.on('browser-window-blur', () => {
remote.globalShortcut.unregister(shortcut)
})
remote.app.on('browser-window-focus', () => {
remote.globalShortcut.register(shortcut, action)
})
remote.globalShortcut.register(shortcut, action)
}

// Set a plugin as the visible plugin
export const setCurrentPlugin = (pluginName) => {
const currentElements = document.querySelectorAll('.current')
Expand All @@ -51,7 +63,7 @@ export const setCurrentPlugin = (pluginName) => {
buttonElem.classList.add('current')
}
remote.globalShortcut.unregister(devtoolsShortcut)
remote.globalShortcut.register(devtoolsShortcut, () => {
registerLocalShortcut(devtoolsShortcut, () => {
viewElem.openDevTools()
})
}
Expand Down Expand Up @@ -83,7 +95,7 @@ export const loadPlugin = (pluginPath, hidden = false, shortcut) => {
const buttonElement = createPluginButtonElement(iconPath, name)

if (typeof shortcut !== 'undefined') {
remote.globalShortcut.register(shortcut, () => {
registerLocalShortcut(shortcut, () => {
setCurrentPlugin(name)
})
}
Expand Down