2019-12-24 06:56:23 -09:00
|
|
|
import {app, Menu, BrowserWindow} from 'electron';
|
2019-11-28 05:17:01 -09:00
|
|
|
import {openConfig, getConfig} from './config';
|
|
|
|
|
import {updatePlugins} from './plugins';
|
|
|
|
|
import {installCLI} from './utils/cli-install';
|
2021-01-24 07:44:04 -09:00
|
|
|
import * as systemContextMenu from './utils/system-context-menu';
|
2017-11-02 18:51:18 -08:00
|
|
|
|
2019-12-24 06:56:23 -09:00
|
|
|
const commands: Record<string, (focusedWindow?: BrowserWindow) => void> = {
|
2017-11-02 18:51:18 -08:00
|
|
|
'window:new': () => {
|
|
|
|
|
// If window is created on the same tick, it will consume event too
|
|
|
|
|
setTimeout(app.createWindow, 0);
|
|
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'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
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'pane:splitRight': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('split request vertical', {});
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'pane:splitDown': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('split request horizontal', {});
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'pane:close': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('termgroup close req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
|
|
|
|
'window:preferences': () => {
|
2021-03-28 08:42:20 -08:00
|
|
|
void openConfig();
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:clearBuffer': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session clear req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:selectAll': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('term selectAll');
|
2018-01-21 02:21:16 -09:00
|
|
|
},
|
2017-11-02 18:51:18 -08:00
|
|
|
'plugins:update': () => {
|
|
|
|
|
updatePlugins();
|
|
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'window:reload': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('reload');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'window:reloadFull': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.reload();
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -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'});
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'zoom:reset': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('reset fontSize req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'zoom:in': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('increase fontSize req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'zoom:out': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('decrease fontSize req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'tab:prev': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('move left req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'tab:next': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('move right req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'pane:prev': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('prev pane req');
|
2017-11-02 18:51:18 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'pane:next': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('next pane req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:movePreviousWord': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session move word left req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:moveNextWord': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session move word right req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:moveBeginningLine': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session move line beginning req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:moveEndLine': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session move line end req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:deletePreviousWord': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session del word left req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:deleteNextWord': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session del word right req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:deleteBeginningLine': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session del line beginning req');
|
2017-11-06 11:27:25 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:deleteEndLine': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session del line end req');
|
2017-12-18 07:17:20 -09:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:break': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session break req');
|
2018-04-22 12:13:23 -08:00
|
|
|
},
|
2020-12-09 21:21:47 -09:00
|
|
|
'editor:stop': (focusedWindow) => {
|
|
|
|
|
focusedWindow?.rpc.emit('session stop req');
|
|
|
|
|
},
|
|
|
|
|
'editor:quit': (focusedWindow) => {
|
|
|
|
|
focusedWindow?.rpc.emit('session quit req');
|
|
|
|
|
},
|
|
|
|
|
'editor:tmux': (focusedWindow) => {
|
|
|
|
|
focusedWindow?.rpc.emit('session tmux req');
|
|
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:search': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session search');
|
2019-09-23 09:37:22 -08:00
|
|
|
},
|
2020-03-25 02:15:08 -08:00
|
|
|
'editor:search-close': (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('session search close');
|
2019-09-23 09:37:22 -08:00
|
|
|
},
|
2018-04-22 12:13:23 -08:00
|
|
|
'cli:install': () => {
|
2021-03-28 08:42:20 -08:00
|
|
|
void installCLI(true);
|
2019-03-30 18:39:43 -08:00
|
|
|
},
|
|
|
|
|
'window:hamburgerMenu': () => {
|
2020-06-26 06:04:15 -08:00
|
|
|
if (process.platform !== 'darwin' && ['', true].includes(getConfig().showHamburgerMenu)) {
|
|
|
|
|
Menu.getApplicationMenu()!.popup({x: 25, y: 22});
|
2019-03-30 18:39:43 -08:00
|
|
|
}
|
2021-01-24 07:44:04 -09:00
|
|
|
},
|
|
|
|
|
'systemContextMenu:add': () => {
|
|
|
|
|
systemContextMenu.add();
|
|
|
|
|
},
|
|
|
|
|
'systemContextMenu:remove': () => {
|
|
|
|
|
systemContextMenu.remove();
|
2021-02-07 02:40:18 -09:00
|
|
|
},
|
|
|
|
|
'window:toggleKeepOnTop': (focusedWindow) => {
|
|
|
|
|
focusedWindow?.setAlwaysOnTop(!focusedWindow.isAlwaysOnTop());
|
2017-11-02 18:51:18 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Special numeric command
|
2020-03-25 02:15:08 -08:00
|
|
|
([1, 2, 3, 4, 5, 6, 7, 8, 'last'] as const).forEach((cmdIndex) => {
|
2017-11-02 18:51:18 -08:00
|
|
|
const index = cmdIndex === 'last' ? cmdIndex : cmdIndex - 1;
|
2020-03-25 02:15:08 -08:00
|
|
|
commands[`tab:jump:${cmdIndex}`] = (focusedWindow) => {
|
2020-03-25 02:22:23 -08:00
|
|
|
focusedWindow?.rpc.emit('move jump req', index);
|
2017-11-02 18:51:18 -08:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-24 06:56:23 -09:00
|
|
|
export const execCommand = (command: string, focusedWindow?: BrowserWindow) => {
|
2017-11-02 18:51:18 -08:00
|
|
|
const fn = commands[command];
|
|
|
|
|
if (fn) {
|
|
|
|
|
fn(focusedWindow);
|
|
|
|
|
}
|
|
|
|
|
};
|