diff --git a/emain/emain-util.ts b/emain/emain-util.ts index ffdffb3705..16fbf93670 100644 --- a/emain/emain-util.ts +++ b/emain/emain-util.ts @@ -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 = 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("+"); +} diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 9f3112616b..7cc076ad50 100644 --- a/emain/emain-window.ts +++ b/emain/emain-window.ts @@ -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); + } +} diff --git a/emain/emain.ts b/emain/emain.ts index 487f17c223..c5cf985bed 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -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) => { diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 6f007767cc..76b6c00fe9 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -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; diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 40c40f592c..b01c8fdff7 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -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" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index 5b64adae7f..3992e5bda9 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -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"`