mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Keybindings second wave - System Keybindings (#386)
* added system level keybindings * added process key event * added fix for code check * add event.returnValue, remove console.logs, change sendSync to send
This commit is contained in:
parent
29acdc6eff
commit
036b0ff989
@ -354,8 +354,6 @@ function createMainWindow(clientData: ClientDataType | null): Electron.BrowserWi
|
||||
e.preventDefault();
|
||||
if (!input.alt) {
|
||||
win.webContents.send("i-cmd", mods);
|
||||
} else {
|
||||
win.webContents.toggleDevTools();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -520,6 +518,13 @@ app.on("window-all-closed", () => {
|
||||
if (unamePlatform !== "darwin") app.quit();
|
||||
});
|
||||
|
||||
electron.ipcMain.on("toggle-developer-tools", (event) => {
|
||||
if (MainWindow != null) {
|
||||
MainWindow.webContents.toggleDevTools();
|
||||
}
|
||||
event.returnValue = true;
|
||||
});
|
||||
|
||||
electron.ipcMain.on("get-id", (event) => {
|
||||
event.returnValue = instanceId + ":" + event.processId;
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
let { contextBridge, ipcRenderer } = require("electron");
|
||||
|
||||
contextBridge.exposeInMainWorld("api", {
|
||||
toggleDeveloperTools: () => ipcRenderer.send("toggle-developer-tools"),
|
||||
getId: () => ipcRenderer.sendSync("get-id"),
|
||||
getPlatform: () => ipcRenderer.sendSync("get-platform"),
|
||||
getIsDev: () => ipcRenderer.sendSync("get-isdev"),
|
||||
|
@ -19,7 +19,7 @@ import { WSControl } from "./ws";
|
||||
import { cmdStatusIsRunning } from "@/app/line/lineutil";
|
||||
import * as appconst from "@/app/appconst";
|
||||
import { remotePtrToString, cmdPacketString } from "@/util/modelutil";
|
||||
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, setKeyUtilPlatform } from "@/util/keyutil";
|
||||
import { KeybindManager, checkKeyPressed, adaptFromReactOrNativeKeyEvent, setKeyUtilPlatform } from "@/util/keyutil";
|
||||
import { Session } from "./session";
|
||||
import { ScreenLines } from "./screenlines";
|
||||
import { InputModel } from "./input";
|
||||
@ -107,6 +107,7 @@ class Model {
|
||||
remotesModel: RemotesModel;
|
||||
lineHeightEnv: LineHeightEnv;
|
||||
|
||||
keybindManager: KeybindManager;
|
||||
inputModel: InputModel;
|
||||
pluginsModel: PluginsModel;
|
||||
bookmarksModel: BookmarksModel;
|
||||
@ -141,6 +142,7 @@ class Model {
|
||||
this.runUpdate(message, interactive);
|
||||
});
|
||||
this.ws.reconnect();
|
||||
this.keybindManager = new KeybindManager();
|
||||
this.inputModel = new InputModel(this);
|
||||
this.pluginsModel = new PluginsModel(this);
|
||||
this.bookmarksModel = new BookmarksModel(this);
|
||||
@ -169,6 +171,13 @@ class Model {
|
||||
}
|
||||
return fontSize;
|
||||
});
|
||||
this.keybindManager.registerKeybinding("system", "electron", "any", (waveEvent) => {
|
||||
if (this.keybindManager.checkKeyPressed(waveEvent, "system:toggleDeveloperTools")) {
|
||||
getApi().toggleDeveloperTools();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
getApi().onTCmd(this.onTCmd.bind(this));
|
||||
getApi().onICmd(this.onICmd.bind(this));
|
||||
getApi().onLCmd(this.onLCmd.bind(this));
|
||||
@ -487,6 +496,7 @@ class Model {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
this.keybindManager.processKeyEvent(e, waveEvent);
|
||||
}
|
||||
|
||||
deleteActiveLine(): boolean {
|
||||
|
1
src/types/custom.d.ts
vendored
1
src/types/custom.d.ts
vendored
@ -878,6 +878,7 @@ declare global {
|
||||
};
|
||||
|
||||
type ElectronApi = {
|
||||
toggleDeveloperTools: () => void;
|
||||
getId: () => string;
|
||||
getIsDev: () => boolean;
|
||||
getPlatform: () => string;
|
||||
|
@ -17,7 +17,7 @@ type KeyPressDecl = {
|
||||
keyType: string;
|
||||
};
|
||||
|
||||
const KeyTypeCodeRegex = /:c{(.*)}/;
|
||||
const KeyTypeCodeRegex = /c{(.*)}/;
|
||||
const KeyTypeKey = "key";
|
||||
const KeyTypeCode = "code";
|
||||
|
||||
@ -44,9 +44,7 @@ class KeybindManager {
|
||||
if (this.checkKeyPressed(event, curKeybind.keybinding)) {
|
||||
let shouldReturn = false;
|
||||
if (curKeybind.callback != null) {
|
||||
console.log("Calling callback", curKeybind.domain);
|
||||
shouldReturn = curKeybind.callback(event);
|
||||
console.log("callback return value", shouldReturn);
|
||||
}
|
||||
if (!shouldReturn && this.domainCallbacks.has(curKeybind.domain)) {
|
||||
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
|
||||
@ -69,7 +67,7 @@ class KeybindManager {
|
||||
processKeyEvent(nativeEvent: any, event: WaveKeyboardEvent) {
|
||||
let modalLevel = this.levelMap.get("modal");
|
||||
if (modalLevel.length != 0) {
|
||||
console.log("processing modal");
|
||||
// console.log("processing modal");
|
||||
// special case when modal keybindings are present
|
||||
let shouldReturn = this.processLevel(nativeEvent, event, modalLevel);
|
||||
if (shouldReturn) {
|
||||
@ -163,7 +161,7 @@ class KeybindManager {
|
||||
for (let index = 0; index < keybindsArray.length; index++) {
|
||||
let curKeybind = keybindsArray[index];
|
||||
if (curKeybind.domain == domain && keybindingIsEqual(curKeybind.keybinding, keybinding)) {
|
||||
console.log("unregistering keybinding");
|
||||
// console.log("unregistering keybinding");
|
||||
keybindsArray.splice(index, 1);
|
||||
index--;
|
||||
this.levelMap.set(level, keybindsArray);
|
||||
|
Loading…
Reference in New Issue
Block a user