waveterm/emain/globalhotkey.ts
Evan Simkowitz 6db414a0f0
Save
2024-09-30 20:55:10 -07:00

22 lines
666 B
TypeScript

import { FileService } from "@/app/store/services";
import { fireAndForget } from "@/util/util";
import { app, globalShortcut } from "electron";
async function hotkeyCallback() {
app.focus();
}
export async function configureGlobalHotkey() {
const settings = (await FileService.GetFullConfig())?.settings;
const globalhotkey = settings["window:globalhotkey"];
if (globalhotkey) {
console.log(`Registering global hotkey: "${globalhotkey}"`);
await app.whenReady();
globalShortcut.register(globalhotkey, () => fireAndForget(() => hotkeyCallback()));
}
app.on("before-quit", () => globalShortcut.unregisterAll());
}