2019-03-30 18:39:43 -08:00
|
|
|
const {app, Menu} = require('electron');
|
|
|
|
|
const {openConfig, getConfig} = require('./config');
|
2017-11-02 18:51:18 -08:00
|
|
|
const {updatePlugins} = require('./plugins');
|
2018-04-22 12:13:23 -08:00
|
|
|
const {installCLI} = require('./utils/cli-install');
|
2017-11-02 18:51:18 -08:00
|
|
|
|
|
|
|
|
const commands = {
|
|
|
|
|
'window:new': () => {
|
|
|
|
|
// If window is created on the same tick, it will consume event too
|
|
|
|
|
setTimeout(app.createWindow, 0);
|
|
|
|
|
},
|
|
|
|
|
'tab:new': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
if (focusedWindow) {
|
2019-10-14 16:09:30 -08:00
|
|
|
focusedWindow.rpc.emit('termgroup add req', {});
|
2017-11-22 04:29:33 -09:00
|
|
|
} else {
|
|
|
|
|
setTimeout(app.createWindow, 0);
|
|
|
|
|
}
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2019-07-30 14:03:33 -08:00
|
|
|
'pane:splitRight': focusedWindow => {
|
2019-10-14 16:09:30 -08:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('split request vertical', {});
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2019-07-30 14:03:33 -08:00
|
|
|
'pane:splitDown': focusedWindow => {
|
2019-10-14 16:09:30 -08:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('split request horizontal', {});
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'pane:close': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('termgroup close req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'window:preferences': () => {
|
|
|
|
|
openConfig();
|
|
|
|
|
},
|
|
|
|
|
'editor:clearBuffer': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session clear req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2018-01-21 02:21:16 -09:00
|
|
|
'editor:selectAll': focusedWindow => {
|
|
|
|
|
focusedWindow.rpc.emit('term selectAll');
|
|
|
|
|
},
|
2017-11-02 18:51:18 -08:00
|
|
|
'plugins:update': () => {
|
|
|
|
|
updatePlugins();
|
|
|
|
|
},
|
|
|
|
|
'window:reload': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('reload');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'window:reloadFull': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.reload();
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'window:devtools': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
if (!focusedWindow) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-02 18:51:18 -08:00
|
|
|
const webContents = focusedWindow.webContents;
|
|
|
|
|
if (webContents.isDevToolsOpened()) {
|
|
|
|
|
webContents.closeDevTools();
|
|
|
|
|
} else {
|
|
|
|
|
webContents.openDevTools({mode: 'detach'});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'zoom:reset': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('reset fontSize req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'zoom:in': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('increase fontSize req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'zoom:out': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('decrease fontSize req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'tab:prev': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('move left req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'tab:next': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('move right req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'pane:prev': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('prev pane req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'pane:next': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('next pane req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:movePreviousWord': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session move word left req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:moveNextWord': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session move word right req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:moveBeginningLine': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session move line beginning req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:moveEndLine': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session move line end req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:deletePreviousWord': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session del word left req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:deleteNextWord': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session del word right req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:deleteBeginningLine': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session del line beginning req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
|
|
|
|
'editor:deleteEndLine': focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('session del line end req');
|
2017-12-18 07:17:20 -09:00
|
|
|
},
|
|
|
|
|
'editor:break': focusedWindow => {
|
|
|
|
|
focusedWindow && focusedWindow.rpc.emit('session break req');
|
2018-04-22 12:13:23 -08:00
|
|
|
},
|
2019-09-23 09:37:22 -08:00
|
|
|
'editor:search': focusedWindow => {
|
|
|
|
|
focusedWindow && focusedWindow.rpc.emit('session search');
|
|
|
|
|
},
|
|
|
|
|
'editor:search-close': focusedWindow => {
|
|
|
|
|
focusedWindow && focusedWindow.rpc.emit('session search close');
|
|
|
|
|
},
|
2018-04-22 12:13:23 -08:00
|
|
|
'cli:install': () => {
|
|
|
|
|
installCLI(true);
|
2019-03-30 18:39:43 -08:00
|
|
|
},
|
|
|
|
|
'window:hamburgerMenu': () => {
|
|
|
|
|
if (getConfig().showHamburgerMenu) {
|
|
|
|
|
Menu.getApplicationMenu().popup({x: 15, y: 15});
|
|
|
|
|
}
|
2017-11-02 18:51:18 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Special numeric command
|
|
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8, 'last'].forEach(cmdIndex => {
|
|
|
|
|
const index = cmdIndex === 'last' ? cmdIndex : cmdIndex - 1;
|
|
|
|
|
commands[`tab:jump:${cmdIndex}`] = focusedWindow => {
|
2017-11-22 04:29:33 -09:00
|
|
|
focusedWindow && focusedWindow.rpc.emit('move jump req', index);
|
2017-11-02 18:51:18 -08:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
exports.execCommand = (command, focusedWindow) => {
|
|
|
|
|
const fn = commands[command];
|
|
|
|
|
if (fn) {
|
|
|
|
|
fn(focusedWindow);
|
|
|
|
|
}
|
|
|
|
|
};
|