diff --git a/app/config.js b/app/config.js index 6c400908566c..f6a0fb925108 100644 --- a/app/config.js +++ b/app/config.js @@ -23,39 +23,32 @@ const _watch = function () { }); }; -const _subscribe = function (fn) { +exports.subscribe = function (fn) { watchers.push(fn); return () => { watchers.splice(watchers.indexOf(fn), 1); }; }; -const _getPlugins = function () { +exports.getPlugins = function () { return { plugins: cfg.plugins, localPlugins: cfg.localPlugins }; }; -const _getConfig = function () { +exports.getConfig = function () { return cfg.config; }; -const _getKeymaps = function () { +exports.getKeymaps = function () { return cfg.keymaps; }; -const _setup = function() { +exports.setup = function () { cfg = _import(); _watch(); }; -module.exports = { - setup: _setup, - subscribe: _subscribe, - getPlugins: _getPlugins, - getConfig: _getConfig, - getKeymaps: _getKeymaps, - getWin: win.get, - winRecord: win.recordState -}; +exports.getWin = win.get; +exports.winRecord = win.recordState; diff --git a/app/config/import.js b/app/config/import.js index 335bff05f497..30ef136f7257 100644 --- a/app/config/import.js +++ b/app/config/import.js @@ -2,6 +2,7 @@ const {writeFileSync, readFileSync} = require('fs'); const {sync: mkdirpSync} = require('mkdirp'); const _paths = require('./paths'); const _init = require('./init'); +const _keys = require('./keymaps'); const _write = function (path, data) { // This method will take text formatted as Unix line endings and transform it @@ -38,7 +39,9 @@ const _importPlugins = function () { const _import = function () { mkdirpSync(_paths.hyperHomeDirPath); _importPlugins(); - return _init(_importConfig()); + const cfg = _init(_importConfig()); + cfg.keymaps = _keys(cfg.keymaps); + return cfg; }; module.exports = _import; diff --git a/app/config/keymaps.js b/app/config/keymaps.js new file mode 100644 index 000000000000..695683640530 --- /dev/null +++ b/app/config/keymaps.js @@ -0,0 +1,39 @@ +const {readFileSync} = require('fs'); +const {join} = require('path'); +const _paths = require('./paths'); + +const _keys = function (customsKeys) { + const commands = {}; + const keys = {}; + const path = () => { + switch (process.platform) { + case 'darwin': return join(_paths.keymapPath, 'darwin.json'); + case 'win32': return join(_paths.keymapPath, 'win32.json'); + case 'linux': return join(_paths.keymapPath, 'linux.json'); + default: return join(_paths.keymapPath, 'darwin.json'); + } + }; + try { + const cmds = JSON.parse(readFileSync(path())); + for (const command in cmds) { + if (command) { + commands[command] = cmds[command]; + keys[commands[command]] = command; + } + } + + if (customsKeys) { + for (const command in customsKeys) { + if (command) { + commands[command] = customsKeys[command]; + keys[customsKeys[command]] = command; + } + } + } + + return {commands, keys}; + } catch (err) { + } +}; + +module.exports = _keys; diff --git a/app/config/paths.js b/app/config/paths.js index b33235c2dedf..ba4711e54d39 100644 --- a/app/config/paths.js +++ b/app/config/paths.js @@ -1,19 +1,19 @@ // This module exports paths, names, and other metadata that is referenced -const path = require('path'); +const {join} = require('path'); const {homedir} = require('os'); const isDev = require('electron-is-dev'); const homeDirPath = homedir(); -const repositoryRootPath = path.resolve(__dirname, '..'); -const hyperHomeDirPath = path.join(homeDirPath, '.hyper'); -const preferencesPath = path.join(hyperHomeDirPath, 'config.js'); -const pluginsPath = path.join(hyperHomeDirPath, 'plugins'); -const keymapPath = path.join(hyperHomeDirPath, 'keymap.js'); -const localPluginsPath = path.join(pluginsPath, 'local'); -const previousConfigPath = path.join(homeDirPath, '.hyper.js'); -const dotHyperPath = path.join(repositoryRootPath, 'dot-hyper'); -const dotConfigPath = path.join(dotHyperPath, 'config-default.js'); -const pkgPath = path.join(pluginsPath, 'package.json'); +const repositoryRootPath = join(__dirname, '..'); +const hyperHomeDirPath = join(homeDirPath, '.hyper'); +const preferencesPath = join(hyperHomeDirPath, 'config.js'); +const pluginsPath = join(hyperHomeDirPath, 'plugins'); +const keymapPath = join(repositoryRootPath, 'keymaps'); +const localPluginsPath = join(pluginsPath, 'local'); +const previousConfigPath = join(homeDirPath, '.hyper.js'); +const dotHyperPath = join(repositoryRootPath, 'dot-hyper'); +const dotConfigPath = join(dotHyperPath, 'config-default.js'); +const pkgPath = join(pluginsPath, 'package.json'); module.exports = { isDev, repositoryRootPath, homeDirPath, hyperHomeDirPath, preferencesPath, pluginsPath, diff --git a/app/index.js b/app/index.js index c443099b529c..2cf00c3eb736 100644 --- a/app/index.js +++ b/app/index.js @@ -62,13 +62,13 @@ config.setup(); const plugins = require('./plugins'); const Session = require('./session'); -const keymaps = require('./keymaps'); const windowSet = new Set([]); // expose to plugins app.config = config; app.plugins = plugins; + app.getWindows = () => new Set([...windowSet]); // return a clone // function to retrieve the last focused window in windowSet; @@ -118,6 +118,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { // previous window. This also ensures in multi monitor setups that the // new terminal is on the correct screen. const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow(); + // In case of options defaults position and size, we should ignore the focusedWindow. if (winPos !== undefined) { [startX, startY] = winPos; @@ -354,6 +355,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { // the window can be closed by the browser process itself win.on('close', () => { config.winRecord(win); + windowSet.delete(win); rpc.destroy(); deleteSessions(); cfgUnsubscribe(); @@ -390,8 +392,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { }); const makeMenu = () => { - const menu = new AppMenu(keymaps.commands, createWindow, () => { - // plugins.update({force: true}); + const menu = new AppMenu(config.getKeymaps().commands, createWindow, () => { plugins.updatePlugins({force: true}); }); diff --git a/app/keymaps.js b/app/keymaps.js deleted file mode 100644 index 515a6fa86fe0..000000000000 --- a/app/keymaps.js +++ /dev/null @@ -1,4 +0,0 @@ -const KeymapManager = require('./keymaps/keymap-manager'); -const config = require('./config'); - -module.exports = new KeymapManager(config.getKeymaps()); \ No newline at end of file diff --git a/app/keymaps/darwin.json b/app/keymaps/darwin.json index 6403d05384e9..3dcda6be9d5d 100644 --- a/app/keymaps/darwin.json +++ b/app/keymaps/darwin.json @@ -1,33 +1,33 @@ { - "window:devtools":"Cmd+Alt+I", - "window:reload":"Cmd+R", - "window:reloadFull":"Cmd+Shift+R", - "window:preferences":"Cmd+,", - "zoom:reset":"Cmd+0", - "zoom:in":"Cmd+plus", - "zoom:out":"Cmd+-", - "window:new":"Cmd+N", - "window:minimize": "Cmd+M", - "window:full": "Cmd+Ctrl+F", - "window:close":"Cmd+Shift+W", + "window:devtools":"cmd+alt+i", + "window:reload":"cmd+r", + "window:reloadFull":"cmd+shift+r", + "window:preferences":"cmd+,", + "zoom:reset":"cmd+0", + "zoom:in":"cmd+plus", + "zoom:out":"cmd+-", + "window:new":"cmd+n", + "window:minimize": "cmd+m", + "window:full": "cmd+ctrl+f", + "window:close":"cmd+shift+w", - "tab:new":"Cmd+T", - "tab:next":"Cmd+shift+]", - "tab:prev":"Cmd+shift+[", - "pane:next":"Cmd+]", - "pane:prev":"Cmd+[", - "pane:vertical":"Cmd+D", - "pane:horizontal":"Cmd+Shift+D", - "pane:close":"Cmd+W", + "tab:new":"cmd+t", + "tab:next":"cmd+shift+]", + "tab:prev":"cmd+shift+[", + "pane:next":"cmd+]", + "pane:prev":"cmd+[", + "pane:vertical":"cmd+d", + "pane:horizontal":"cmd+shift+d", + "pane:close":"cmd+w", - "editor:undo":"Cmd+Z", - "editor:redo":"Cmd+Y", - "editor:cut":"Cmd+X", - "editor:copy":"Cmd+C", - "editor:paste":"Cmd+V", - "editor:selectAll":"Cmd+A", - "editor:clearBuffer":"Cmd+K", - "editor:emojis": "Cmd+Ctrl+Space", + "editor:undo":"cmd+z", + "editor:redo":"cmd+y", + "editor:cut":"cmd+x", + "editor:copy":"cmd+c", + "editor:paste":"cmd+v", + "editor:selectAll":"cmd+a", + "editor:clearBuffer":"cmd+k", + "editor:emojis": "cmd+ctrl+space", - "plugins:update": "Cmd+Shift+U" + "plugins:update": "cmd+shift+u" } \ No newline at end of file diff --git a/app/keymaps/keymap-manager.js b/app/keymaps/keymap-manager.js deleted file mode 100644 index dcf551fb2be5..000000000000 --- a/app/keymaps/keymap-manager.js +++ /dev/null @@ -1,72 +0,0 @@ -const {readFileSync} = require('fs'); -const {resolve} = require('path'); - -module.exports = class KeymapManager { - constructor(customsKeys) { - this.platform = process.platform; - this.commands = {}; - this.keys = {}; - - const path = () => { - switch (this.platform) { - case 'darwin': return resolve(__dirname, 'darwin.json'); - case 'win32': return resolve(__dirname, 'win32.json'); - case 'linux': return resolve(__dirname, 'linux.json'); - default: return resolve(__dirname, 'darwin.json'); - } - }; - - try { - const commands = JSON.parse(readFileSync(path())); - for (const command in commands) { - if (command) { - this.commands[command] = commands[command]; - this.keys[commands[command]] = command; - } - } - this.extract(customsKeys); - } catch (err) { - - } - } - - extract(keys) { - Object.keys(keys).map(key => { - this.commands[key] = keys[key]; - this.keys[fileKEYS[key]] = key; - }); - } - - // decides if a keybard event is in Hyper keymap - isCommands(e) { - console.log(e); - let keys = []; - if (e.metaKey && this.platform === 'darwin') { - keys.push('Cmd'); - } else if (e.metaKey) { - keys.push(e.key); - } - - if (e.ctrlKey) { - keys.push('Ctrl'); - } - - if (e.shiftKey) { - keys.push('Shift'); - } - - if (e.altKey) { - keys.push('Alt'); - } - if (e.key === ' ') { - keys.push('space'); - } else if (e.key !== 'Meta' && e.key !== 'Control' && e.key !== 'Shift' && e.key !== 'Alt') { - keys.push(e.key.replace('Arrow', '')); - } - - keys = keys.join('+'); - - return this.keys[keys]; - } - -}; diff --git a/app/keymaps/linux.json b/app/keymaps/linux.json index e089791038ef..b42d6f43a01f 100644 --- a/app/keymaps/linux.json +++ b/app/keymaps/linux.json @@ -1,32 +1,32 @@ { - "window:devtools":"Ctrl+Shift+I", - "window:reload":"Ctrl+Shift+R", - "window:reloadFull":"Ctrl+Shift+F5", - "window:preferences":"Ctrl+,", - "zoom:reset":"Ctrl+0", - "zoom:in":"Ctrl+plus", - "zoom:out":"Ctrl+-", - "window:new":"Ctrl+Shift+N", - "window:minimize": "Ctrl+M", - "window:full": "F11", - "window:close":"Ctrl+Shift+W", + "window:devtools":"ctrl+shift+i", + "window:reload":"ctrl+shift+r", + "window:reloadFull":"ctrl+shift+f5", + "window:preferences":"ctrl+,", + "zoom:reset":"ctrl+0", + "zoom:in":"ctrl+plus", + "zoom:out":"ctrl+-", + "window:new":"ctrl+shift+n", + "window:minimize": "ctrl+m", + "window:full": "f11", + "window:close":"ctrl+shift+w", - "tab:new":"Ctrl+Shift+T", - "tab:next":"Ctrl+Tab", - "tab:prev":"Ctrl+shift+Tab", - "pane:next":"Ctrl+Pageup", - "pane:prev":"Ctrl+Pagedown", - "pane:vertical":"Ctrl+Shift+D", - "pane:horizontal":"Ctrl+Shift+E", - "pane:close":"Ctrl+Shift+W", + "tab:new":"ctrl+shift+t", + "tab:next":"ctrl+tab", + "tab:prev":"ctrl+shift+tab", + "pane:next":"ctrl+pageup", + "pane:prev":"ctrl+pagedown", + "pane:vertical":"ctrl+shift+d", + "pane:horizontal":"ctrl+shift+e", + "pane:close":"ctrl+shift+w", - "editor:undo":"Ctrl+Shift+Z", - "editor:redo":"Ctrl+Shift+Y", - "editor:cut":"Ctrl+Shift+X", - "editor:copy":"Ctrl+Shift+C", - "editor:paste":"Ctrl+Shift+V", - "editor:selectAll":"Ctrl+Shift+A", - "editor:clearBuffer":"Ctrl+Shift+K", + "editor:undo":"ctrl+shift+z", + "editor:redo":"ctrl+shift+y", + "editor:cut":"ctrl+shift+x", + "editor:copy":"ctrl+shift+c", + "editor:paste":"ctrl+shift+v", + "editor:selectAll":"ctrl+shift+a", + "editor:clearBuffer":"ctrl+shift+k", - "plugins:update": "Ctrl+Shift+U" + "plugins:update": "ctrl+shift+u" } \ No newline at end of file diff --git a/app/keymaps/win32.json b/app/keymaps/win32.json index d8a5320b069a..9623e0505bf8 100644 --- a/app/keymaps/win32.json +++ b/app/keymaps/win32.json @@ -1,32 +1,32 @@ { - "window:devtools":"Ctrl+Shift+I", - "window:reload":"Ctrl+Shift+R", - "window:reloadFull":"Ctrl+Shift+F5", - "window:preferences":"Ctrl+,", - "zoom:reset":"Ctrl+0", - "zoom:in":"Ctrl+plus", - "zoom:out":"Ctrl+-", - "window:new":"Ctrl+Shift+N", - "window:minimize": "Ctrl+M", - "window:full": "F11", - "window:close":"Ctrl+Shift+W", + "window:devtools":"ctrl+shift+i", + "window:reload":"ctrl+shift+r", + "window:reloadFull":"ctrl+shift+f5", + "window:preferences":"ctrl+,", + "zoom:reset":"ctrl+0", + "zoom:in":"ctrl+plus", + "zoom:out":"ctrl+-", + "window:new":"ctrl+shift+n", + "window:minimize": "ctrl+M", + "window:full": "f11", + "window:close":"ctrl+shift+w", - "tab:new":"Ctrl+Shift+T", - "tab:next":"Ctrl+Tab", - "tab:prev":"Ctrl+shift+Tab", - "pane:next":"Ctrl+Pageup", - "pane:prev":"Ctrl+Pagedown", - "pane:vertical":"Ctrl+Shift+D", - "pane:horizontal":"Ctrl+Shift+E", - "pane:close":"Ctrl+Shift+W", + "tab:new":"ctrl+shift+t", + "tab:next":"ctrl+tab", + "tab:prev":"ctrl+shift+tab", + "pane:next":"ctrl+pageup", + "pane:prev":"ctrl+pagedown", + "pane:vertical":"ctrl+shift+d", + "pane:horizontal":"ctrl+shift+e", + "pane:close":"ctrl+shift+w", - "editor:undo":"Ctrl+Shift+Z", - "editor:redo":"Ctrl+Shift+Y", - "editor:cut":"Ctrl+Shift+X", - "editor:copy":"Ctrl+Shift+C", - "editor:paste":"Ctrl+Shift+V", - "editor:selectAll":"Ctrl+Shift+A", - "editor:clearBuffer":"Ctrl+Shift+K", + "editor:undo":"ctrl+shift+z", + "editor:redo":"ctrl+shift+y", + "editor:cut":"ctrl+shift+x", + "editor:copy":"ctrl+shift+c", + "editor:paste":"ctrl+shift+v", + "editor:selectAll":"ctrl+shift+a", + "editor:clearBuffer":"ctrl+shift+k", - "plugins:update": "Ctrl+Shift+U" + "plugins:update": "ctrl+shift+u" } \ No newline at end of file diff --git a/app/plugins.js b/app/plugins.js index 262a2164c95a..895fa0b72254 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -9,7 +9,7 @@ let modules; const _fetch = ({force = false} = {}) => { utils.init(err => { - (() => { + const clearCache = function(() => { // trigger unload hooks modules.forEach(mod => { if (mod.onUnload) { @@ -23,6 +23,7 @@ const _fetch = ({force = false} = {}) => { } } }); + clearCache(); modules = utils.load(); if (utils.versionChanged(modules.length)) { notify( @@ -38,14 +39,14 @@ modules = utils.load(() => { _fetch(); }); -const _subscribe = function (fn) { +exports.subscribe = function (fn) { watchers.push(fn); return () => { watchers.splice(watchers.indexOf(fn), 1); }; }; -const _update = function ({force = false} = {}) { +exports.updatePlugins = function ({force = false} = {}) { if (utils.shouldUpdate()) { _fetch({force}); } @@ -69,24 +70,24 @@ function decorateObject(base, key) { return decorated; } -const _decorateMenu = function (tpl) { +exports.decorateMenu = function (tpl) { return decorateObject(tpl, 'decorateMenu'); }; -const _getDecoratedEnv = function (baseEnv) { +exports.getDecoratedEnv = function (baseEnv) { return decorateObject(baseEnv, 'decorateEnv'); }; -const _getDecoratedConfig = function () { +exports.getDecoratedConfig = function () { const baseConfig = config.getConfig(); return decorateObject(baseConfig, 'decorateConfig'); }; -const _getDecoratedBrowserOptions = function (defaults) { +exports.getDecoratedBrowserOptions = function (defaults) { return decorateObject(defaults, 'decorateBrowserOptions'); }; -const _onApp = function (app) { +exports.onApp = function (app) { modules.forEach(plugin => { if (plugin.onApp) { plugin.onApp(app); @@ -94,7 +95,7 @@ const _onApp = function (app) { }); }; -const _onWindow = function (win) { +exports.onWindow = function (win) { modules.forEach(plugin => { if (plugin.onWindow) { plugin.onWindow(win); @@ -103,7 +104,7 @@ const _onWindow = function (win) { }; // get paths from renderer -const _getBasePaths = function () { +exports.getBasePaths = function () { return {path: pluginsPath, localPath: localPluginsPath}; }; @@ -116,15 +117,18 @@ config.subscribe(() => { } }); -module.exports = { - updatePlugins: _update, - getBasePaths: _getBasePaths, // get paths from renderer - getPaths: utils.getPaths, // expose to renderer - subscribe: _subscribe, - decorateMenu: _decorateMenu, - onApp: _onApp, - onWindow: _onWindow, - getDecoratedEnv: _getDecoratedEnv, - getDecoratedConfig: _getDecoratedConfig, - getDecoratedBrowserOptions: _getDecoratedBrowserOptions -}; +exports.getPaths = utils.getPaths; + +// module.exports = { +// updatePlugins: _update, +// getBasePaths: _getBasePaths, // get paths from renderer +// getPaths: utils.getPaths, // expose to renderer +// subscribe: _subscribe, +// decorateMenu: _decorateMenu, +// onApp: _onApp, +// onWindow: _onWindow, +// getDecoratedEnv: _getDecoratedEnv, +// getDecoratedConfig: _getDecoratedConfig, +// getDecoratedBrowserOptions: _getDecoratedBrowserOptions, +// // getDecoratedKeymaps: _decorateKeymaps +// }; diff --git a/app/plugins/init.js b/app/plugins/init.js index aef8a68ef4f0..0a69c3df8396 100644 --- a/app/plugins/init.js +++ b/app/plugins/init.js @@ -80,11 +80,6 @@ function init(fn) { 'Error updating plugins.', 'We could not find the `npm` command. Make sure it\'s in $PATH' ); - } else { - notify( - 'Error updating plugins.', - 'Check `~/.hyper_plugins/npm-debug.log` for more information.' - ); } } else { cache.set('hyper.plugins4', _plugins); diff --git a/app/plugins/install.js b/app/plugins/install.js index 4e352305d725..4267854d86c7 100644 --- a/app/plugins/install.js +++ b/app/plugins/install.js @@ -46,7 +46,9 @@ const _syncPackageJSON = function (plugins) { const _command = function (plugins, cfg, fn) { _syncPackageJSON(plugins); - const {npmRegistry, cfgShell} = cfg; + const {shell: cfgShell, npmRegistry} = cfg; + const shell = cfgShell && cfgShell !== '' ? cfgShell : undefined; + shellEnv().then(env => { if (npmRegistry) { env.NPM_CONFIG_REGISTRY = npmRegistry; diff --git a/lib/hterm.js b/lib/hterm.js index 9853ac7bc46e..bfb556b2d251 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -3,6 +3,7 @@ import {hterm, lib} from 'hterm-umdjs'; import runes from 'runes'; import fromCharCode from './utils/key-code'; import selection from './utils/selection'; +import isCommands from './utils/keymaps'; hterm.defaultStorage = new lib.Storage.Memory(); @@ -229,8 +230,7 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) { e.preventDefault(); } // hterm shouldn't consume a hyper accelerator - // if (e.altKey || e.metaKey || window.keymaps.isCommands(e)) { - if (e.altKey || e.metaKey) { + if (e.altKey || e.metaKey || isCommands(e)) { // If the `hyperCaret` was removed on `selectAll`, we need to insert it back if (e.key === 'v' && this.terminal.hyperCaret.parentNode !== this.terminal.cursorNode_) { this.terminal.focusHyperCaret(); diff --git a/lib/index.js b/lib/index.js index e1e5d9e357c1..accffa187e56 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,8 +4,6 @@ import {Provider} from 'react-redux'; import React from 'react'; import {render} from 'react-dom'; -import KeymapManager from '../app/keymaps/keymap-manager'; - import rpc from './rpc'; import init from './actions/index'; import * as config from './utils/config'; @@ -18,14 +16,12 @@ import {addNotificationMessage} from './actions/notifications'; import {loadConfig, reloadConfig} from './actions/config'; import HyperContainer from './containers/hyper'; import configureStore from './store/configure-store'; -import keymaps from './utils/keymaps'; // Disable pinch zoom webFrame.setZoomLevelLimits(1, 1); const store_ = configureStore(); -window.keymaps = keymaps; window.store = store_; window.rpc = rpc; window.config = config; diff --git a/lib/utils/keymaps.js b/lib/utils/keymaps.js index b23e5fcd9537..05c09e2694d2 100644 --- a/lib/utils/keymaps.js +++ b/lib/utils/keymaps.js @@ -1,5 +1,34 @@ import {remote} from 'electron'; -// TODO make isCommads work... -const keymaps = remote.require('./keymaps'); -console.log(keymaps.commands); +const {getKeymaps} = remote.require('./config'); + +export default function isCommands(e) { + let keys = []; + + if (e.metaKey && process.platform === 'darwin') { + keys.push('cmd'); + } else if (e.metaKey) { + keys.push(e.key); + } + + if (e.ctrlKey) { + keys.push('ctrl'); + } + + if (e.shiftKey) { + keys.push('shift'); + } + + if (e.altKey) { + keys.push('alt'); + } + + if (e.key === ' ') { + keys.push('space'); + } else if (e.key !== 'Meta' && e.key !== 'Control' && e.key !== 'Shift' && e.key !== 'Alt') { + keys.push(e.key.replace('Arrow', '')); + } + + keys = keys.join('+'); + return getKeymaps().keys[keys]; +}