MCPcopy
hub / github.com/game1024/OpenSpeedy / SettingsManager

Function SettingsManager

src/components/SettingsManager.tsx:35–213  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33// ── Component ─────────────────────────────────────────────────────────────
34
35export default function SettingsManager() {
36 const { t } = useTranslation();
37 const { settings, get, set } = useSettings();
38 const { register, unregister } = useShortcut();
39 const { notify } = useSnackbar();
40
41 // Sync auto-start state from system on mount
42 useEffect(() => { isEnabled().then(v => set("autoStart", v)).catch(() => { }); }, []);
43
44 async function changeShortcut(key: keyof SettingsState, oldVal: string, newVal: string, cb: () => void) {
45 if (oldVal) await unregister(oldVal).catch(() => { });
46 if (newVal) {
47 try {
48 await register(newVal, cb);
49 notify(t("settings.registerSuccess", { shortcut: newVal }), "success");
50 } catch {
51 notify(t("settings.registerFail", { shortcut: newVal }), "error");
52 }
53 }
54 await set(key as keyof SettingsState, newVal);
55 }
56
57 if (!settings) {
58 return <Box sx={{ flex: 1, display: "flex", alignItems: "center", justifyContent: "center" }}>
59 <Typography color="text.disabled">{t("settings.loading")}</Typography>
60 </Box>;
61 }
62
63 return (
64 <Box sx={{ height: "calc(100vh - 48px)", overflow: "auto", px: 2, pb: 2 }}>
65 <Paper elevation={0} sx={{ mt: 2, p: 2, bgcolor: "background.paper", border: 1, borderColor: "divider" }}>
66
67 {/* ── 速度快捷键 ── */}
68 <Table size="small">
69 <colgroup>
70 <col />
71 <col width={240} />
72 <col width={80} />
73 </colgroup>
74 <TableHead>
75 <TableRow>
76 <TableCell>
77 <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
78 <SpeedIcon sx={{ color: "secondary.main", fontSize: 18 }} />
79 <Typography variant="subtitle2" sx={{ fontWeight: 600, textTransform: "uppercase", letterSpacing: 0.5, color: "text.secondary" }}>
80 {t("settings.speedShortcuts")}
81 </Typography>
82 </Box>
83 </TableCell>
84 <TableCell>{t("settings.shortcut")}</TableCell>
85 <TableCell>{t("settings.step")}</TableCell>
86 </TableRow>
87 </TableHead>
88 <TableBody>
89 <TableRow>
90 <TableCell sx={{ borderBottom: "none" }}>{t("settings.increase")}</TableCell>
91 <TableCell sx={{ borderBottom: "none" }}>
92 <ShortcutField value={settings.increaseSpeedShortcut} onChange={v => changeShortcut("increaseSpeedShortcut", settings.increaseSpeedShortcut, v, () => {

Callers

nothing calls this directly

Calls 4

useSettingsFunction · 0.90
useShortcutFunction · 0.90
useSnackbarFunction · 0.90
changeShortcutFunction · 0.85

Tested by

no test coverage detected