mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Global Hotkey (#1534)
Sets up a configurable global hotkey to focus the last window used in the application. Note that this is established at startup and configuration changes will not be applied until rebooting the app.
This commit is contained in:
parent
99b5a08a2e
commit
51bd45bd2b
@ -166,3 +166,24 @@ export function ensureBoundsAreVisible(bounds: electron.Rectangle): electron.Rec
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
export function waveKeyToElectronKey(waveKey: string): string {
|
||||
const waveParts = waveKey.split(":");
|
||||
const electronParts: Array<string> = waveParts.map((part: string) => {
|
||||
if (part == "ArrowUp") {
|
||||
return "Up";
|
||||
}
|
||||
if (part == "ArrowDown") {
|
||||
return "Down";
|
||||
}
|
||||
if (part == "ArrowLeft") {
|
||||
return "Left";
|
||||
}
|
||||
if (part == "ArrowRight") {
|
||||
return "Right";
|
||||
}
|
||||
|
||||
return part;
|
||||
});
|
||||
return electronParts.join("+");
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
import { ClientService, FileService, ObjectService, WindowService, WorkspaceService } from "@/app/store/services";
|
||||
import { fireAndForget } from "@/util/util";
|
||||
import { BaseWindow, BaseWindowConstructorOptions, dialog, ipcMain, screen } from "electron";
|
||||
import { BaseWindow, BaseWindowConstructorOptions, dialog, globalShortcut, ipcMain, screen } from "electron";
|
||||
import path from "path";
|
||||
import { debounce } from "throttle-debounce";
|
||||
import {
|
||||
@ -14,7 +14,7 @@ import {
|
||||
setWasInFg,
|
||||
} from "./emain-activity";
|
||||
import { getOrCreateWebViewForTab, getWaveTabViewByWebContentsId, WaveTabView } from "./emain-tabview";
|
||||
import { delay, ensureBoundsAreVisible } from "./emain-util";
|
||||
import { delay, ensureBoundsAreVisible, waveKeyToElectronKey } from "./emain-util";
|
||||
import { log } from "./log";
|
||||
import { getElectronAppBasePath, unamePlatform } from "./platform";
|
||||
import { updater } from "./updater";
|
||||
@ -766,3 +766,23 @@ export async function relaunchBrowserWindows() {
|
||||
win.show();
|
||||
}
|
||||
}
|
||||
|
||||
export function registerGlobalHotkey(rawGlobalHotKey: string) {
|
||||
try {
|
||||
const electronHotKey = waveKeyToElectronKey(rawGlobalHotKey);
|
||||
console.log("registering globalhotkey of ", electronHotKey);
|
||||
globalShortcut.register(electronHotKey, () => {
|
||||
const selectedWindow = focusedWaveWindow;
|
||||
const firstWaveWindow = getAllWaveWindows()[0];
|
||||
if (focusedWaveWindow) {
|
||||
selectedWindow.focus();
|
||||
} else if (firstWaveWindow) {
|
||||
firstWaveWindow.focus();
|
||||
} else {
|
||||
fireAndForget(createNewWaveWindow);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("error registering global hotkey: ", e);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import {
|
||||
getWaveWindowById,
|
||||
getWaveWindowByWebContentsId,
|
||||
getWaveWindowByWorkspaceId,
|
||||
registerGlobalHotkey,
|
||||
relaunchBrowserWindows,
|
||||
WaveBrowserWindow,
|
||||
} from "./emain-window";
|
||||
@ -610,6 +611,10 @@ async function appMain() {
|
||||
fireAndForget(createNewWaveWindow);
|
||||
}
|
||||
});
|
||||
const rawGlobalHotKey = launchSettings?.["key:globalhotkey"];
|
||||
if (rawGlobalHotKey) {
|
||||
registerGlobalHotkey(rawGlobalHotKey);
|
||||
}
|
||||
}
|
||||
|
||||
appMain().catch((e) => {
|
||||
|
2
frontend/types/gotypes.d.ts
vendored
2
frontend/types/gotypes.d.ts
vendored
@ -657,6 +657,8 @@ declare global {
|
||||
"window:magnifiedblocksize"?: number;
|
||||
"window:magnifiedblockblurprimarypx"?: number;
|
||||
"window:magnifiedblockblursecondarypx"?: number;
|
||||
"key:*"?: boolean;
|
||||
"key:globalhotkey"?: string;
|
||||
"telemetry:*"?: boolean;
|
||||
"telemetry:enabled"?: boolean;
|
||||
"conn:*"?: boolean;
|
||||
|
@ -69,6 +69,9 @@ const (
|
||||
ConfigKey_WindowMagnifiedBlockBlurPrimaryPx = "window:magnifiedblockblurprimarypx"
|
||||
ConfigKey_WindowMagnifiedBlockBlurSecondaryPx = "window:magnifiedblockblursecondarypx"
|
||||
|
||||
ConfigKey_KeyClear = "key:*"
|
||||
ConfigKey_KeyGlobalHotkey = "key:globalhotkey"
|
||||
|
||||
ConfigKey_TelemetryClear = "telemetry:*"
|
||||
ConfigKey_TelemetryEnabled = "telemetry:enabled"
|
||||
|
||||
|
@ -96,6 +96,9 @@ type SettingsType struct {
|
||||
WindowMagnifiedBlockBlurPrimaryPx *int64 `json:"window:magnifiedblockblurprimarypx,omitempty"`
|
||||
WindowMagnifiedBlockBlurSecondaryPx *int64 `json:"window:magnifiedblockblursecondarypx,omitempty"`
|
||||
|
||||
KeyClear bool `json:"key:*,omitempty"`
|
||||
KeyGlobalHotkey string `json:"key:globalhotkey,omitempty"`
|
||||
|
||||
TelemetryClear bool `json:"telemetry:*,omitempty"`
|
||||
TelemetryEnabled bool `json:"telemetry:enabled,omitempty"`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user