-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathKeyboardImplementationSelector.tsx
More file actions
79 lines (69 loc) · 2.65 KB
/
KeyboardImplementationSelector.tsx
File metadata and controls
79 lines (69 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React from "react";
import { useTranslation } from "react-i18next";
import { type } from "@tauri-apps/plugin-os";
import { SettingContainer } from "../../ui/SettingContainer";
import { Dropdown, type DropdownOption } from "../../ui/Dropdown";
import { useSettings } from "../../../hooks/useSettings";
import { commands } from "@/bindings";
import { toast } from "sonner";
// "None" is Linux-only: Tauri + Handy Keys both work reliably on macOS and Windows,
// so exposing an option that disables all built-in hotkeys there would be a footgun.
// On Linux (particularly Wayland) the compositor-keybind workflow is a legitimate fallback.
const isLinux = type() === "linux";
const KEYBOARD_IMPLEMENTATION_OPTIONS: DropdownOption[] = [
{ value: "tauri", label: "Tauri Global Shortcut" },
{ value: "handy_keys", label: "Handy Keys" },
...(isLinux
? [{ value: "none", label: "None (Compositor Only)" } as DropdownOption]
: []),
];
interface KeyboardImplementationSelectorProps {
descriptionMode?: "tooltip" | "inline";
grouped?: boolean;
}
export const KeyboardImplementationSelector: React.FC<
KeyboardImplementationSelectorProps
> = ({ descriptionMode = "tooltip", grouped = false }) => {
const { t } = useTranslation();
const { getSetting, isUpdating, refreshSettings } = useSettings();
const currentImplementation =
getSetting("keyboard_implementation") ?? "tauri";
const handleSelect = async (value: string) => {
if (value === currentImplementation) return;
try {
const result = await commands.changeKeyboardImplementationSetting(value);
if (result.status === "error") {
console.error(
"Failed to update keyboard implementation:",
result.error,
);
toast.error(String(result.error));
return;
}
// If any bindings were reset due to incompatibility, notify the user
if (result.data.reset_bindings.length > 0) {
toast.warning(t("settings.debug.keyboardImplementation.bindingsReset"));
}
await refreshSettings();
} catch (error) {
console.error("Failed to update keyboard implementation:", error);
toast.error(String(error));
}
};
return (
<SettingContainer
title={t("settings.debug.keyboardImplementation.title")}
description={t("settings.debug.keyboardImplementation.description")}
descriptionMode={descriptionMode}
grouped={grouped}
layout="horizontal"
>
<Dropdown
options={KEYBOARD_IMPLEMENTATION_OPTIONS}
selectedValue={currentImplementation}
onSelect={handleSelect}
disabled={isUpdating("keyboard_implementation")}
/>
</SettingContainer>
);
};