From 8533de51355cddaf8918b408c59f90a31c0236ad Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Mon, 16 Dec 2024 14:32:35 -0800 Subject: [PATCH 1/3] feat: add basic globalhotkey implementation --- emain/emain-util.ts | 23 +++++++++++++++++++++++ emain/emain.ts | 23 ++++++++++++++++++++++- frontend/types/gotypes.d.ts | 2 ++ pkg/wconfig/metaconsts.go | 3 +++ pkg/wconfig/settingsconfig.go | 3 +++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/emain/emain-util.ts b/emain/emain-util.ts index ffdffb370..2e2261377 100644 --- a/emain/emain-util.ts +++ b/emain/emain-util.ts @@ -166,3 +166,26 @@ export function ensureBoundsAreVisible(bounds: electron.Rectangle): electron.Rec } return bounds; } + +const numberRegexp = new RegExp("^c\{Digit\d{0,9}\}$"); + +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.ts b/emain/emain.ts index 487f17c22..a381de337 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -28,7 +28,7 @@ import { setWasInFg, } from "./emain-activity"; import { ensureHotSpareTab, getWaveTabViewByWebContentsId, setMaxTabCacheSize } from "./emain-tabview"; -import { handleCtrlShiftState } from "./emain-util"; +import { handleCtrlShiftState, waveKeyToElectronKey } from "./emain-util"; import { getIsWaveSrvDead, getWaveSrvProc, getWaveSrvReady, getWaveVersion, runWaveSrv } from "./emain-wavesrv"; import { createBrowserWindow, @@ -610,6 +610,27 @@ async function appMain() { fireAndForget(createNewWaveWindow); } }); + const rawGlobalHotKey = launchSettings?.["key:globalhotkey"]; + if (rawGlobalHotKey) { + try { + const electronHotKey = waveKeyToElectronKey(rawGlobalHotKey); + console.log("registering globalhotkey of ", electronHotKey); + electron.globalShortcut.register(electronHotKey, () => { + const selectedWindow = focusedWaveWindow; + const firstWaveWindow = getAllWaveWindows()[0]; + console.log("the selected window is ", selectedWindow ?? "nonexistent"); + if (focusedWaveWindow) { + selectedWindow.focus(); + } else if (firstWaveWindow) { + firstWaveWindow.focus(); + } else { + fireAndForget(createNewWaveWindow); + } + }); + } catch (e) { + console.log(e); + } + } } appMain().catch((e) => { diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 6f007767c..76b6c00fe 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 40c40f592..b01c8fdff 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 5b64adae7..3992e5bda 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"` From 806aea4f3dcb5dd473a7a40744f39adb75a78506 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Mon, 16 Dec 2024 14:39:46 -0800 Subject: [PATCH 2/3] refactor: move global hotkey logic to emain-window --- emain/emain-window.ts | 24 ++++++++++++++++++++++-- emain/emain.ts | 22 +++------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 9f3112616..7cc076ad5 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 a381de337..c5cf985be 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -28,7 +28,7 @@ import { setWasInFg, } from "./emain-activity"; import { ensureHotSpareTab, getWaveTabViewByWebContentsId, setMaxTabCacheSize } from "./emain-tabview"; -import { handleCtrlShiftState, waveKeyToElectronKey } from "./emain-util"; +import { handleCtrlShiftState } from "./emain-util"; import { getIsWaveSrvDead, getWaveSrvProc, getWaveSrvReady, getWaveVersion, runWaveSrv } from "./emain-wavesrv"; import { createBrowserWindow, @@ -38,6 +38,7 @@ import { getWaveWindowById, getWaveWindowByWebContentsId, getWaveWindowByWorkspaceId, + registerGlobalHotkey, relaunchBrowserWindows, WaveBrowserWindow, } from "./emain-window"; @@ -612,24 +613,7 @@ async function appMain() { }); const rawGlobalHotKey = launchSettings?.["key:globalhotkey"]; if (rawGlobalHotKey) { - try { - const electronHotKey = waveKeyToElectronKey(rawGlobalHotKey); - console.log("registering globalhotkey of ", electronHotKey); - electron.globalShortcut.register(electronHotKey, () => { - const selectedWindow = focusedWaveWindow; - const firstWaveWindow = getAllWaveWindows()[0]; - console.log("the selected window is ", selectedWindow ?? "nonexistent"); - if (focusedWaveWindow) { - selectedWindow.focus(); - } else if (firstWaveWindow) { - firstWaveWindow.focus(); - } else { - fireAndForget(createNewWaveWindow); - } - }); - } catch (e) { - console.log(e); - } + registerGlobalHotkey(rawGlobalHotKey); } } From 33b22f64b43ebc185bf2fc9b085e88ae01da7f31 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Mon, 16 Dec 2024 14:56:13 -0800 Subject: [PATCH 3/3] fix: remove unused regexp --- emain/emain-util.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/emain/emain-util.ts b/emain/emain-util.ts index 2e2261377..16fbf9367 100644 --- a/emain/emain-util.ts +++ b/emain/emain-util.ts @@ -167,8 +167,6 @@ export function ensureBoundsAreVisible(bounds: electron.Rectangle): electron.Rec return bounds; } -const numberRegexp = new RegExp("^c\{Digit\d{0,9}\}$"); - export function waveKeyToElectronKey(waveKey: string): string { const waveParts = waveKey.split(":"); const electronParts: Array = waveParts.map((part: string) => {