新增禁用搜索小键盘设置

This commit is contained in:
JSR
2026-03-18 20:30:49 +08:00
parent c1dc0daedb
commit f54d614316
6 changed files with 94 additions and 6 deletions
+19
View File
@@ -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![]),
+26 -5
View File
@@ -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<SearchKeyboardLayout>("qwerty26")
const [disableSearchKeyboard, setDisableSearchKeyboard] = useState(false)
const scrollContainerRef = useRef<HTMLDivElement>(null)
const groupRefs = useRef<Record<string, HTMLDivElement | null>>({})
@@ -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 }) => {
<Input
value={searchKeyword}
onChange={(e) => 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 && (
<div
style={{
position: "absolute",
+43 -1
View File
@@ -1,5 +1,18 @@
import React, { useEffect, useMemo, useRef, useState } from "react"
import { Tabs, Card, Form, Select, Input, Button, Space, Divider, Tag, Modal, message } from "antd"
import {
Tabs,
Card,
Form,
Select,
Input,
Button,
Space,
Divider,
Tag,
Modal,
Switch,
message,
} from "antd"
import { ThemeQuickSettings } from "./ThemeQuickSettings"
import { useTranslation } from "react-i18next"
import { changeLanguage, getCurrentLanguage, languageOptions, AppLanguage } from "../i18n"
@@ -10,6 +23,7 @@ type appSettings = {
log_level: "debug" | "info" | "warn" | "error"
window_zoom?: string
search_keyboard_layout?: "t9" | "qwerty26"
disable_search_keyboard?: boolean
auto_score_enabled?: boolean
}
@@ -22,6 +36,7 @@ export const Settings: React.FC<{ permission: permissionLevel }> = ({ 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
</div>
</Form.Item>
<Form.Item label={t("settings.searchKeyboard.disableToggle")}>
<Switch
checked={Boolean(settings.disable_search_keyboard)}
onChange={async (checked) => {
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}
/>
<div
style={{ marginTop: "4px", fontSize: "12px", color: "var(--ss-text-secondary)" }}
>
{t("settings.searchKeyboard.disableHint")}
</div>
</Form.Item>
<Form.Item label={t("settings.interfaceZoom")}>
<Select
value={settings.window_zoom || "1.0"}
+2
View File
@@ -130,6 +130,8 @@
"searchKeyboard": {
"title": "Search Keyboard",
"hint": "Choose the pop-up keyboard layout under the search box",
"disableToggle": "Disable Search Keyboard",
"disableHint": "When enabled, the keyboard will no longer pop up below the search box",
"options": {
"qwerty26": "26-key (QWERTY)",
"t9": "9-key (T9)"
+2
View File
@@ -130,6 +130,8 @@
"searchKeyboard": {
"title": "搜索小键盘",
"hint": "选择搜索框下方弹出的小键盘布局",
"disableToggle": "禁用搜索小键盘",
"disableHint": "开启后,搜索框下方不再弹出小键盘",
"options": {
"qwerty26": "26 键(QWERTY",
"t9": "9 键(T9"
+2
View File
@@ -22,6 +22,7 @@ export type settingsKey =
| "log_level"
| "window_zoom"
| "search_keyboard_layout"
| "disable_search_keyboard"
| "themes_custom"
| "auto_score_enabled"
| "auto_score_rules"
@@ -34,6 +35,7 @@ export interface settingsSpec {
log_level: string
window_zoom: number
search_keyboard_layout: "t9" | "qwerty26"
disable_search_keyboard: boolean
themes_custom: themeConfig[]
auto_score_enabled: boolean
auto_score_rules: any[]