From f54d614316c4730f5e13ec41f2c3171606a06383 Mon Sep 17 00:00:00 2001 From: JSR Date: Wed, 18 Mar 2026 20:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A6=81=E7=94=A8=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=B0=8F=E9=94=AE=E7=9B=98=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/services/settings.rs | 19 +++++++++++++ src/components/Home.tsx | 31 +++++++++++++++++---- src/components/Settings.tsx | 44 +++++++++++++++++++++++++++++- src/i18n/locales/en-US.json | 2 ++ src/i18n/locales/zh-CN.json | 2 ++ src/preload/types.ts | 2 ++ 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/services/settings.rs b/src-tauri/src/services/settings.rs index 623d111..eac086b 100644 --- a/src-tauri/src/services/settings.rs +++ b/src-tauri/src/services/settings.rs @@ -9,6 +9,7 @@ pub struct SettingsSpec { pub log_level: String, pub window_zoom: f64, pub search_keyboard_layout: String, + pub disable_search_keyboard: bool, pub themes_custom: JsonValue, pub auto_score_enabled: bool, pub auto_score_rules: JsonValue, @@ -24,6 +25,7 @@ impl Default for SettingsSpec { log_level: "info".to_string(), window_zoom: 1.0, search_keyboard_layout: "qwerty26".to_string(), + disable_search_keyboard: false, themes_custom: JsonValue::Array(vec![]), auto_score_enabled: false, auto_score_rules: JsonValue::Array(vec![]), @@ -40,6 +42,7 @@ pub enum SettingsKey { LogLevel, WindowZoom, SearchKeyboardLayout, + DisableSearchKeyboard, ThemesCustom, AutoScoreEnabled, AutoScoreRules, @@ -55,6 +58,7 @@ impl SettingsKey { SettingsKey::LogLevel => "log_level", SettingsKey::WindowZoom => "window_zoom", SettingsKey::SearchKeyboardLayout => "search_keyboard_layout", + SettingsKey::DisableSearchKeyboard => "disable_search_keyboard", SettingsKey::ThemesCustom => "themes_custom", SettingsKey::AutoScoreEnabled => "auto_score_enabled", SettingsKey::AutoScoreRules => "auto_score_rules", @@ -70,6 +74,7 @@ impl SettingsKey { "log_level" => Some(SettingsKey::LogLevel), "window_zoom" => Some(SettingsKey::WindowZoom), "search_keyboard_layout" => Some(SettingsKey::SearchKeyboardLayout), + "disable_search_keyboard" => Some(SettingsKey::DisableSearchKeyboard), "themes_custom" => Some(SettingsKey::ThemesCustom), "auto_score_enabled" => Some(SettingsKey::AutoScoreEnabled), "auto_score_rules" => Some(SettingsKey::AutoScoreRules), @@ -291,6 +296,16 @@ impl SettingsService { }, ); + defs.insert( + SettingsKey::DisableSearchKeyboard, + SettingDefinition { + kind: SettingValueKind::Boolean, + default_value: SettingsValue::Boolean(false), + write_permission: PermissionRequirement::Admin, + validate: None, + }, + ); + defs.insert( SettingsKey::ThemesCustom, SettingDefinition { @@ -459,6 +474,10 @@ impl SettingsService { SettingsValue::String(s) => s, _ => "qwerty26".to_string(), }, + disable_search_keyboard: match self.get_value(SettingsKey::DisableSearchKeyboard) { + SettingsValue::Boolean(b) => b, + _ => false, + }, themes_custom: match self.get_value(SettingsKey::ThemesCustom) { SettingsValue::Json(j) => j, _ => JsonValue::Array(vec![]), diff --git a/src/components/Home.tsx b/src/components/Home.tsx index 312ccea..b14ed50 100644 --- a/src/components/Home.tsx +++ b/src/components/Home.tsx @@ -64,6 +64,7 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { const [searchKeyword, setSearchKeyword] = useState("") const [showPinyinKeyboard, setShowPinyinKeyboard] = useState(false) const [searchKeyboardLayout, setSearchKeyboardLayout] = useState("qwerty26") + const [disableSearchKeyboard, setDisableSearchKeyboard] = useState(false) const scrollContainerRef = useRef(null) const groupRefs = useRef>({}) @@ -145,12 +146,22 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { }) .catch(() => void 0) + api + .getSetting("disable_search_keyboard") + .then((res: any) => { + if (disposed) return + setDisableSearchKeyboard(Boolean(res?.data)) + }) + .catch(() => void 0) + api .onSettingChanged((change: any) => { - if (change?.key !== "search_keyboard_layout") return - if (change?.value === "t9" || change?.value === "qwerty26") { + if (change?.key === "search_keyboard_layout" && (change?.value === "t9" || change?.value === "qwerty26")) { setSearchKeyboardLayout(change.value) } + if (change?.key === "disable_search_keyboard") { + setDisableSearchKeyboard(Boolean(change?.value)) + } }) .then((fn: () => void) => { if (disposed) { @@ -167,6 +178,12 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { } }, []) + useEffect(() => { + if (disableSearchKeyboard && showPinyinKeyboard) { + setShowPinyinKeyboard(false) + } + }, [disableSearchKeyboard, showPinyinKeyboard]) + useEffect(() => { const onDocumentClick = (e: MouseEvent) => { const target = e.target as Node | null @@ -893,8 +910,12 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { setSearchKeyword(e.target.value)} - onFocus={() => setShowPinyinKeyboard(true)} - onClick={() => setShowPinyinKeyboard(true)} + onFocus={() => { + if (!disableSearchKeyboard) setShowPinyinKeyboard(true) + }} + onClick={() => { + if (!disableSearchKeyboard) setShowPinyinKeyboard(true) + }} onKeyDown={(e) => { if (e.key === "Escape") setShowPinyinKeyboard(false) }} @@ -903,7 +924,7 @@ export const Home: React.FC<{ canEdit: boolean }> = ({ canEdit }) => { allowClear style={{ width: "220px" }} /> - {showPinyinKeyboard && ( + {!disableSearchKeyboard && showPinyinKeyboard && (
= ({ permission log_level: "info", window_zoom: "1.0", search_keyboard_layout: "qwerty26", + disable_search_keyboard: false, }) const [securityStatus, setSecurityStatus] = useState<{ @@ -112,6 +127,8 @@ export const Settings: React.FC<{ permission: permissionLevel }> = ({ permission if (change?.key === "window_zoom") return { ...prev, window_zoom: change.value } if (change?.key === "search_keyboard_layout") return { ...prev, search_keyboard_layout: change.value } + if (change?.key === "disable_search_keyboard") + return { ...prev, disable_search_keyboard: Boolean(change.value) } if (change?.key === "auto_score_enabled") return { ...prev, auto_score_enabled: change.value } return prev @@ -409,6 +426,31 @@ export const Settings: React.FC<{ permission: permissionLevel }> = ({ permission
+ + { + if (!(window as any).api) return + const res = await (window as any).api.setSetting( + "disable_search_keyboard", + checked + ) + if (res.success) { + setSettings((prev) => ({ ...prev, disable_search_keyboard: checked })) + messageApi.success(t("settings.general.saved")) + } else { + messageApi.error(res.message || t("settings.general.saveFailed")) + } + }} + disabled={!canAdmin} + /> +
+ {t("settings.searchKeyboard.disableHint")} +
+
+