accelerators sservice

This commit is contained in:
2026-03-22 02:10:10 +08:00
parent a72430e65f
commit aa9d1f54a1
9 changed files with 642 additions and 641 deletions

View File

@@ -3,34 +3,12 @@
import {
commands,
type AppConfig,
type SceneInteractivityHotkey,
} from "$lib/bindings";
const DEFAULT_HOTKEY: SceneInteractivityHotkey = {
modifiers: ["alt"],
key: null,
};
const normalizeHotkey = (
hotkey: SceneInteractivityHotkey | null | undefined,
): SceneInteractivityHotkey => {
if (!hotkey) return { ...DEFAULT_HOTKEY };
const uniqueModifiers = [...new Set(hotkey.modifiers ?? [])].sort();
if (uniqueModifiers.length === 0) {
return { ...DEFAULT_HOTKEY };
}
return {
modifiers: uniqueModifiers,
key: hotkey.key ?? null,
};
};
let form: AppConfig = {
api_base_url: "",
debug_mode: false,
scene_interactivity_hotkey: { ...DEFAULT_HOTKEY },
accelerators: {},
};
let saving = false;
@@ -44,9 +22,7 @@
form = {
api_base_url: config.api_base_url ?? "",
debug_mode: config.debug_mode ?? false,
scene_interactivity_hotkey: normalizeHotkey(
config.scene_interactivity_hotkey,
),
accelerators: config.accelerators ?? {},
};
} catch (err) {
errorMessage = `Failed to load config: ${err}`;
@@ -85,9 +61,7 @@
await commands.saveClientConfig({
api_base_url: form.api_base_url?.trim() || null,
debug_mode: form.debug_mode,
scene_interactivity_hotkey: normalizeHotkey(
form.scene_interactivity_hotkey,
),
accelerators: form.accelerators ?? {},
});
successMessage = "Success. Restart to apply changes.";