App keybindings (#432)

* added app keybindings

* removed emain cmd-p

* removed boilerplate for emain commands
This commit is contained in:
Cole Lashley 2024-03-12 12:36:52 -07:00 committed by GitHub
parent 2acb551f4b
commit 36de526e8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 114 additions and 80 deletions

View File

@ -39,6 +39,14 @@
"command": "app:openTabSearchModal",
"keys": ["Cmd:p"]
},
{
"command": "app:openConnectionsView",
"keys": []
},
{
"command": "app:openSettingsView",
"keys": []
},
{
"command": "app:newTab",
"keys": ["Cmd:t"]

View File

@ -355,13 +355,6 @@ function createMainWindow(clientData: ClientDataType | null): Electron.BrowserWi
e.preventDefault();
return;
}
if (checkKeyPressed(waveEvent, "Cmd:i")) {
e.preventDefault();
if (!input.alt) {
win.webContents.send("i-cmd", mods);
}
return;
}
if (checkKeyPressed(waveEvent, "Cmd:r")) {
e.preventDefault();
win.webContents.send("r-cmd", mods);
@ -377,16 +370,6 @@ function createMainWindow(clientData: ClientDataType | null): Electron.BrowserWi
win.webContents.send("w-cmd", mods);
return;
}
if (checkKeyPressed(waveEvent, "Cmd:h")) {
win.webContents.send("h-cmd", mods);
e.preventDefault();
return;
}
if (checkKeyPressed(waveEvent, "Cmd:p")) {
win.webContents.send("p-cmd", mods);
e.preventDefault();
return;
}
if (checkKeyPressed(waveEvent, "Cmd:ArrowUp") || checkKeyPressed(waveEvent, "Cmd:ArrowDown")) {
if (checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
win.webContents.send("meta-arrowup");
@ -405,7 +388,7 @@ function createMainWindow(clientData: ClientDataType | null): Electron.BrowserWi
e.preventDefault();
return;
}
if (input.code.startsWith("Digit") && input.meta) {
if (input.code.startsWith("Digit") && input.meta && !input.control) {
const digitNum = parseInt(input.code.substring(5));
if (isNaN(digitNum) || digitNum < 1 || digitNum > 9) {
return;

View File

@ -21,11 +21,8 @@ contextBridge.exposeInMainWorld("api", {
getAppUpdateStatus: () => ipcRenderer.sendSync("get-app-update-status"),
onAppUpdateStatus: (callback) => ipcRenderer.on("app-update-status", (_, val) => callback(val)),
onTCmd: (callback) => ipcRenderer.on("t-cmd", callback),
onICmd: (callback) => ipcRenderer.on("i-cmd", callback),
onLCmd: (callback) => ipcRenderer.on("l-cmd", callback),
onHCmd: (callback) => ipcRenderer.on("h-cmd", callback),
onWCmd: (callback) => ipcRenderer.on("w-cmd", callback),
onPCmd: (callback) => ipcRenderer.on("p-cmd", callback),
onRCmd: (callback) => ipcRenderer.on("r-cmd", callback),
onZoomChanged: (callback) => ipcRenderer.on("zoom-changed", callback),
onMetaArrowUp: (callback) => ipcRenderer.on("meta-arrowup", callback),

View File

@ -146,6 +146,7 @@ class Model {
this.keybindManager = new KeybindManager();
this.readConfigKeybindings();
this.initSystemKeybindings();
this.initAppKeybindings();
this.inputModel = new InputModel(this);
this.pluginsModel = new PluginsModel(this);
this.bookmarksModel = new BookmarksModel(this);
@ -175,10 +176,7 @@ class Model {
return fontSize;
});
getApi().onTCmd(this.onTCmd.bind(this));
getApi().onICmd(this.onICmd.bind(this));
getApi().onLCmd(this.onLCmd.bind(this));
getApi().onHCmd(this.onHCmd.bind(this));
getApi().onPCmd(this.onPCmd.bind(this));
getApi().onWCmd(this.onWCmd.bind(this));
getApi().onRCmd(this.onRCmd.bind(this));
getApi().onZoomChanged(this.onZoomChanged.bind(this));
@ -220,12 +218,49 @@ class Model {
}
initSystemKeybindings() {
this.keybindManager.registerKeybinding("system", "electron", "any", (waveEvent) => {
if (this.keybindManager.checkKeyPressed(waveEvent, "system:toggleDeveloperTools")) {
getApi().toggleDeveloperTools();
this.keybindManager.registerKeybinding("system", "electron", "system:toggleDeveloperTools", (waveEvent) => {
getApi().toggleDeveloperTools();
return true;
});
}
initAppKeybindings() {
for (let index = 1; index <= 9; index++) {
this.keybindManager.registerKeybinding("app", "model", "app:selectWorkspace-" + index, (waveEvent) => {
this.onSwitchSessionCmd(index);
return true;
}
return false;
});
}
this.keybindManager.registerKeybinding("app", "model", "app:focusCmdInput", (waveEvent) => {
console.log("focus cmd input callback");
this.onFocusCmdInputPressed();
return true;
});
this.keybindManager.registerKeybinding("app", "model", "app:bookmarkActiveLine", (waveEvent) => {
this.onBookmarkViewPressed();
return true;
});
this.keybindManager.registerKeybinding("app", "model", "app:openHistory", (waveEvent) => {
this.onOpenHistoryPressed();
return true;
});
this.keybindManager.registerKeybinding("app", "model", "app:openTabSearchModal", (waveEvent) => {
this.onOpenTabSearchModalPressed();
return true;
});
this.keybindManager.registerKeybinding("app", "model", "app:openConnectionsView", (waveEvent) => {
this.onOpenConnectionsViewPressed();
return true;
});
this.keybindManager.registerKeybinding("app", "model", "app:openSettingsView", (waveEvent) => {
this.onOpenSettingsViewPressed();
return true;
});
}
@ -470,56 +505,49 @@ class Model {
}
if (this.activeMainView.get() == "bookmarks") {
this.bookmarksModel.handleDocKeyDown(e);
return;
}
if (this.activeMainView.get() == "history") {
this.historyViewModel.handleDocKeyDown(e);
return;
}
if (this.activeMainView.get() == "connections") {
this.historyViewModel.handleDocKeyDown(e);
return;
}
if (this.activeMainView.get() == "clientsettings") {
this.historyViewModel.handleDocKeyDown(e);
return;
}
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
if (this.activeMainView.get() == "webshare") {
this.showSessionView();
} else {
if (checkKeyPressed(waveEvent, "Escape")) {
e.preventDefault();
if (this.activeMainView.get() == "webshare") {
this.showSessionView();
return;
}
if (this.clearModals()) {
return;
}
const inputModel = this.inputModel;
inputModel.toggleInfoMsg();
if (inputModel.inputMode.get() != null) {
inputModel.resetInputMode();
}
return;
}
if (this.clearModals()) {
return;
}
const inputModel = this.inputModel;
inputModel.toggleInfoMsg();
if (inputModel.inputMode.get() != null) {
inputModel.resetInputMode();
}
return;
}
if (checkKeyPressed(waveEvent, "Cmd:b")) {
e.preventDefault();
GlobalCommandRunner.bookmarksView();
}
if (this.activeMainView.get() == "session" && checkKeyPressed(waveEvent, "Cmd:Ctrl:s")) {
e.preventDefault();
const activeScreen = this.getActiveScreen();
if (activeScreen != null) {
const isSidebarOpen = activeScreen.isSidebarOpen();
if (isSidebarOpen) {
GlobalCommandRunner.screenSidebarClose();
} else {
GlobalCommandRunner.screenSidebarOpen();
if (this.activeMainView.get() == "session" && checkKeyPressed(waveEvent, "Cmd:Ctrl:s")) {
e.preventDefault();
const activeScreen = this.getActiveScreen();
if (activeScreen != null) {
const isSidebarOpen = activeScreen.isSidebarOpen();
if (isSidebarOpen) {
GlobalCommandRunner.screenSidebarClose();
} else {
GlobalCommandRunner.screenSidebarOpen();
}
}
}
}
if (checkKeyPressed(waveEvent, "Cmd:d")) {
const ranDelete = this.deleteActiveLine();
if (ranDelete) {
e.preventDefault();
if (checkKeyPressed(waveEvent, "Cmd:d")) {
const ranDelete = this.deleteActiveLine();
if (ranDelete) {
e.preventDefault();
}
}
}
this.keybindManager.processKeyEvent(e, waveEvent);
@ -719,8 +747,22 @@ class Model {
GlobalCommandRunner.createNewScreen();
}
onICmd(e: any, mods: KeyModsType) {
this.inputModel.giveFocus();
onBookmarkViewPressed() {
GlobalCommandRunner.bookmarksView();
}
onFocusCmdInputPressed() {
if (this.activeMainView.get() != "session") {
mobx.action(() => {
this.activeMainView.set("session");
setTimeout(() => {
// allows for the session view to load
this.inputModel.giveFocus();
}, 100);
})();
} else {
this.inputModel.giveFocus();
}
}
onLCmd(e: any, mods: KeyModsType) {
@ -730,14 +772,22 @@ class Model {
}
}
onHCmd(e: any, mods: KeyModsType) {
onOpenHistoryPressed() {
this.historyViewModel.reSearch();
}
onPCmd(e: any, mods: KeyModsType) {
onOpenTabSearchModalPressed() {
this.modalsModel.pushModal(appconst.TAB_SWITCHER);
}
onOpenConnectionsViewPressed() {
this.activeMainView.set("connections");
}
onOpenSettingsViewPressed() {
this.activeMainView.set("clientsettings");
}
getFocusedLine(): LineFocusType {
if (this.inputModel.hasFocus()) {
return { cmdInputFocus: true };
@ -804,11 +854,12 @@ class Model {
}
}
onSwitchSessionCmd(digit: number) {
console.log("switching to ", digit);
GlobalCommandRunner.switchSession(String(digit));
}
onDigitCmd(e: any, arg: { digit: number }, mods: KeyModsType) {
if (mods.meta && mods.ctrl) {
GlobalCommandRunner.switchSession(String(arg.digit));
return;
}
GlobalCommandRunner.switchScreen(String(arg.digit));
}

View File

@ -896,10 +896,7 @@ declare global {
getAppUpdateStatus: () => AppUpdateStatusType;
onAppUpdateStatus: (callback: (status: AppUpdateStatusType) => void) => void;
onTCmd: (callback: (mods: KeyModsType) => void) => void;
onICmd: (callback: (mods: KeyModsType) => void) => void;
onLCmd: (callback: (mods: KeyModsType) => void) => void;
onHCmd: (callback: (mods: KeyModsType) => void) => void;
onPCmd: (callback: (mods: KeyModsType) => void) => void;
onRCmd: (callback: (mods: KeyModsType) => void) => void;
onWCmd: (callback: (mods: KeyModsType) => void) => void;
onZoomChanged: (callback: () => void) => void;

View File

@ -3,7 +3,7 @@ import * as mobx from "mobx";
import * as electron from "electron";
import { parse } from "node:path";
import { v4 as uuidv4 } from "uuid";
import defaultKeybindingsFile from "../../assets/keybindings.json";
import defaultKeybindingsFile from "../../assets/default-keybindings.json";
const defaultKeybindings: KeybindConfig = defaultKeybindingsFile;
type KeyPressDecl = {
@ -68,7 +68,6 @@ class KeybindManager {
let curUserCommand = "";
if (this.userKeybindings != null && this.userKeybindings instanceof Array) {
try {
console.log("setting user keybindings");
for (let index = 0; index < this.userKeybindings.length; index++) {
let curKeybind = this.userKeybindings[index];
if (curKeybind == null) {
@ -97,7 +96,6 @@ class KeybindManager {
}
}
this.keyDescriptionsMap = newKeyDescriptions;
console.log("key desc map:", this.keyDescriptionsMap);
}
processLevel(nativeEvent: any, event: WaveKeyboardEvent, keybindsArray: Array<Keybind>): boolean {