2022-02-22 10:05:21 +01:00
|
|
|
import { globalShortcut } from "electron";
|
|
|
|
import settings, { SettingsData } from "./settings";
|
|
|
|
import { emitCameraToggle, emitMuteToggle } from "./ipc";
|
2022-02-22 14:00:17 +01:00
|
|
|
import { createAndShowNotification } from "./notification";
|
|
|
|
|
|
|
|
export function setShortcutsEnabled(enabled: boolean) {
|
|
|
|
if (enabled) {
|
|
|
|
loadShortcuts();
|
|
|
|
} else {
|
|
|
|
globalShortcut.unregisterAll();
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 10:05:21 +01:00
|
|
|
|
|
|
|
export function loadShortcuts() {
|
|
|
|
globalShortcut.unregisterAll();
|
|
|
|
|
|
|
|
const shortcuts = settings.get("shortcuts");
|
|
|
|
|
|
|
|
// // mute key
|
|
|
|
if (shortcuts?.mute_toggle && shortcuts.mute_toggle.length > 0) {
|
|
|
|
globalShortcut.register(shortcuts.mute_toggle, () => {
|
|
|
|
emitMuteToggle();
|
2022-02-22 14:00:17 +01:00
|
|
|
createAndShowNotification({ body: "Toggled mute" }); // TODO
|
2022-02-22 10:05:21 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shortcuts?.camera_toggle && shortcuts.camera_toggle.length > 0) {
|
|
|
|
globalShortcut.register(shortcuts.camera_toggle, () => {
|
|
|
|
emitCameraToggle();
|
2022-02-22 14:00:17 +01:00
|
|
|
createAndShowNotification({ body: "Toggled camera" }); // TODO
|
2022-02-22 10:05:21 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveShortcut(shortcut: keyof SettingsData["shortcuts"], key: string | null) {
|
|
|
|
const shortcuts = settings.get("shortcuts") || <SettingsData["shortcuts"]>{};
|
|
|
|
shortcuts[shortcut] = key;
|
|
|
|
settings.set("shortcuts", shortcuts);
|
|
|
|
loadShortcuts();
|
|
|
|
}
|