diff --git a/app/index.js b/app/index.js index 226cd366..9213a3c7 100644 --- a/app/index.js +++ b/app/index.js @@ -200,14 +200,10 @@ app.on('ready', () => Menu.setApplicationMenu(AppMenu.buildMenu(menu)); }; - const load = () => { - plugins.onApp(app); - plugins.checkDeprecatedExtendKeymaps(); - makeMenu(); - }; - - load(); - plugins.subscribe(load); + plugins.onApp(app); + makeMenu(); + plugins.subscribe(plugins.onApp.bind(undefined, app)); + config.subscribe(makeMenu); }) .catch(err => { //eslint-disable-next-line no-console diff --git a/app/plugins.js b/app/plugins.js index 01678c4e..b98e2f82 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -43,6 +43,15 @@ config.subscribe(() => { } }); +function checkDeprecatedExtendKeymaps() { + modules.forEach(plugin => { + if (plugin.extendKeymaps) { + notify('Plugin warning!', `"${plugin._name}" use deprecated "extendKeymaps" handler`); + return; + } + }); +} + let updating = false; function updatePlugins({force = false} = {}) { @@ -84,6 +93,7 @@ function updatePlugins({force = false} = {}) { } else { notify('Plugins Updated', 'No changes!'); } + checkDeprecatedExtendKeymaps(); watchers.forEach(fn => fn(err, {force})); } } @@ -347,15 +357,6 @@ exports.getDecoratedConfig = () => { return translatedConfig; }; -exports.checkDeprecatedExtendKeymaps = () => { - modules.forEach(plugin => { - if (plugin.extendKeymaps) { - notify('Plugin warning!', `"${plugin._name}" use deprecated "extendKeymaps" handler`); - return; - } - }); -}; - exports.getDecoratedKeymaps = () => { const baseKeymaps = config.getKeymaps(); // Ensure that all keys are in an array and don't use deprecated key combination` diff --git a/app/ui/contextmenu.js b/app/ui/contextmenu.js index 2291476e..a854ba39 100644 --- a/app/ui/contextmenu.js +++ b/app/ui/contextmenu.js @@ -4,11 +4,12 @@ const {execCommand} = require('../commands'); const {getDecoratedKeymaps} = require('../plugins'); const separator = {type: 'separator'}; -const allCommandKeys = getDecoratedKeymaps(); -const commandKeys = Object.keys(allCommandKeys).reduce((result, command) => { - result[command] = allCommandKeys[command][0]; - return result; -}, {}); +const getCommandKeys = keymaps => + Object.keys(keymaps).reduce((commandKeys, command) => { + return Object.assign(commandKeys, { + [command]: keymaps[command][0] + }); + }, {}); // only display cut/copy when there's a cursor selection const filterCutCopy = (selection, menuItem) => { @@ -19,6 +20,7 @@ const filterCutCopy = (selection, menuItem) => { }; module.exports = (createWindow, selection) => { + const commandKeys = getCommandKeys(getDecoratedKeymaps()); const _shell = shellMenu(commandKeys, execCommand).submenu; const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection)); return _edit.concat(separator, _shell).filter(menuItem => !menuItem.hasOwnProperty('enabled') || menuItem.enabled); diff --git a/lib/actions/config.js b/lib/actions/config.js index 61c8b772..260b3e4b 100644 --- a/lib/actions/config.js +++ b/lib/actions/config.js @@ -8,8 +8,10 @@ export function loadConfig(config) { } export function reloadConfig(config) { + const now = Date.now(); return { type: CONFIG_RELOAD, - config + config, + now }; } diff --git a/lib/containers/hyper.js b/lib/containers/hyper.js index 142aa837..2b347c43 100644 --- a/lib/containers/hyper.js +++ b/lib/containers/hyper.js @@ -20,6 +20,9 @@ class Hyper extends PureComponent { this.handleFocusActive = this.handleFocusActive.bind(this); this.onTermsRef = this.onTermsRef.bind(this); this.mousetrap = null; + this.state = { + lastConfigUpdate: 0 + }; } componentWillReceiveProps(next) { @@ -28,6 +31,11 @@ class Hyper extends PureComponent { // starts working again document.body.style.backgroundColor = next.backgroundColor; } + const {lastConfigUpdate} = next; + if (lastConfigUpdate && lastConfigUpdate !== this.state.lastConfigUpdate) { + this.setState({lastConfigUpdate}); + this.attachKeyListeners(); + } } handleFocusActive() { @@ -132,7 +140,8 @@ const HyperContainer = connect( borderColor: state.ui.borderColor, activeSession: state.sessions.activeUid, backgroundColor: state.ui.backgroundColor, - maximized: state.ui.maximized + maximized: state.ui.maximized, + lastConfigUpdate: state.ui._lastUpdate }; }, dispatch => { diff --git a/lib/reducers/ui.js b/lib/reducers/ui.js index 9f0dd17d..09f24ef7 100644 --- a/lib/reducers/ui.js +++ b/lib/reducers/ui.js @@ -103,7 +103,7 @@ const reducer = (state = initial, action) => { case CONFIG_LOAD: // eslint-disable-next-line no-case-declarations, no-fallthrough case CONFIG_RELOAD: - const {config} = action; + const {config, now} = action; state_ = state // unset the user font size override if the // font size changed from the config @@ -205,6 +205,8 @@ const reducer = (state = initial, action) => { ret.quickEdit = config.quickEdit; } + ret._lastUpdate = now; + return ret; })() );