Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

refactor(setting, iframe): 重构模块结构与统一管理缩放逻辑

hairyf7dcc24039263
diff --git a/src/hooks/use-iframe-post.ts b/src/hooks/use-iframe-post.ts
index 8a96282a..dae3f1fc 100644
--- a/src/hooks/use-iframe-post.ts
+++ b/src/hooks/use-iframe-post.ts
@@ -1,3 +1,4 @@
+/* eslint-disable react/no-unnecessary-use-prefix */
import type { RefObject } from 'react'
import { getIframeOrigin } from '@/utils/iframe'
@@ -6,7 +7,7 @@ export const IFRAME_HOST_SOURCE = 'dsh-desktop'
/** 宿主 → iframe 的消息体:`type` 必填(如 `dsh://sidebar:toggle`),其余字段按具体协议附带。 */
export interface IframeOutboundMessage {
- type: string
+ type?: string
[key: string]: unknown
}
diff --git a/src/hooks/use-sync-visibility.ts b/src/hooks/use-sync-visibility.ts
new file mode 100644
index 00000000..2e943cc0
--- /dev/null
+++ b/src/hooks/use-sync-visibility.ts
@@ -0,0 +1,63 @@
+/* eslint-disable react/exhaustive-deps */
+import { useIntervalFn } from '@reause/core'
+import { getCurrentWindow } from '@tauri-apps/api/window'
+import { useEffect } from 'react'
+import { useIframePost } from './use-iframe-post'
+
+const VISIBILITY_POLL_INTERVAL = 5000
+const appWindow = getCurrentWindow()
+
+export function useSyncVisibility(iframeRef: React.RefObject<HTMLIFrameElement | null>) {
+ const post = useIframePost(iframeRef)
+
+ function syncVisibility() {
+ void (async () => {
+ try {
+ const appWindow = getCurrentWindow()
+ const [minimized, visible] = await Promise.all([
+ appWindow.isMinimized(),
+ appWindow.isVisible(),
+ ])
+ post({ type: 'dsh://visibility-state', hidden: minimized || !visible })
+ }
+ catch (error) {
+ console.error('[notification] sync visibility failed:', error)
+ }
+ })()
+ }
+
+ // 窗口焦点/尺寸变化时即时同步可见性(Tauri 窗口事件非 `listen`,保留 effect 承担注销)
+ useEffect(() => {
+ let disposed = false
+ let unlisteners: Array<() => void> = []
+ void (async () => {
+ try {
+ syncVisibility()
+ const unFocus = await appWindow.onFocusChanged(() => {
+ void syncVisibility()
+ })
+ const unResized = await appWindow.onResized(() => {
+ void syncVisibility()
+ })
+ // 订阅完成前若已卸载则立即释放,避免回调泄漏
+ if (disposed) {
+ unFocus()
+ unResized()
+ }
+ else {
+ unlisteners = [unFocus, unResized]
+ }
+ }
+ catch (error) {
+ console.error('[notification] visibility listeners failed:', error)
+ }
+ })()
+ return () => {
+ disposed = true
+ unlisteners.forEach(fn => fn())
+ }
+ }, [])
+
+ // 兜底轮询:覆盖监听不到的状态变化(如任务栏切换);主路径是窗口焦点/尺寸事件
+ useIntervalFn(syncVisibility, VISIBILITY_POLL_INTERVAL)
+}
diff --git a/src/layout/components/iframe.tsx b/src/layout/components/iframe.tsx
index 213775e8..7ff26bf8 100644
--- a/src/layout/components/iframe.tsx
+++ b/src/layout/components/iframe.tsx
@@ -1,11 +1,8 @@
/* eslint-disable react/dom-no-unsafe-iframe-sandbox */
import type { RefObject } from 'react'
-import type { ZoomAction } from '@/utils/zoom'
import { CircleExclamation } from '@gravity-ui/icons'
-import { useEventListener, useIntervalFn } from '@reause/core'
+import { useEventListener } from '@reause/core'
import { invoke } from '@tauri-apps/api/core'
-import { getCurrentWindow } from '@tauri-apps/api/window'
-import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { If } from 'react-if-lite'
import { useStore } from 'valtio-define'
@@ -15,12 +12,12 @@ import { useIframeMessage } from '@/hooks/use-iframe-message'
import { useIframePost } from '@/hooks/use-iframe-post'
import { useInvokeIframe } from '@/hooks/use-invoke-iframe'
import { useListen } from '@/hooks/use-listen'
+import { useSyncVisibility } from '@/hooks/use-sync-visibility'
import { useZoomFactor } from '@/hooks/use-zoom-factor'
import { store } from '@/store'
-import { nextZoomFactor, zoomActionFromBridgeMessage, zoomActionFromShortcut } from '@/utils/zoom'
+import { zoomActionFromBridgeMessage, zoomActionFromShortcut } from '@/utils/zoom'
import { Loadable } from './loadable'
/** 可见性兜底轮询间隔:主路径是窗口 focus/resize 事件,5s 足以覆盖任务栏切换等场景 */
-const VISIBILITY_POLL_INTERVAL = 5000
/**
* iframe → 宿主 的桥消息(宿主侧按 `type` 分发,不比对 `source`)。
@@ -48,111 +45,53 @@ export interface IframeProps {
iframeRef: RefObject<HTMLIFrameElement | null>
}
-/**
- * 主区域 iframe:元素、加载/失败覆盖层,以及 iframe 自身的一整套桥。
- *
- * - 出站:`useIframePost`(origin 定向 + `source: 'dsh-desktop'` 协议标识);
- * - 入站:`useIframeMessage`(直接 iframe + origin 校验)+ 一个 `switch (type)`
- * (原生通知 / 插件异常上报 / 剪贴板图片回退 / 插件 boot 状态 / 缩放快捷键);
- * - 缩放:真值放在 `store.setting.zoom_factor`(persist 插件写入的 `setting` 键与
- * Rust 共用同一份 `.store.dat`,重启后由 Rust 在窗口创建时按同一规则应用),
- * 壳层快捷键与 iframe 缩放桥只更新该真值,把它落到 WebView 由 `useZoomFactor`
- * 负责(挂载一次 + 值变化时重应用);若平台没有原生缩放能力则跳过应用;
- * - 附加桥:Tauri invoke 转发 `useInvokeIframe`;
- * - 系统通知点击回传、窗口可见性同步(focus/resize + 兜底轮询)。
- *
- * 侧边栏导航桥(`dsh://sidebar:collapsed` / `dsh://sidebar:toggle`)不在这里——
- * 它属于壳层导航栏的状态,由 `webview.tsx` 用同一份 post/message 处理。
- *
- * 加载失败时**保持 iframe 挂载**,用覆盖层提供重试,重试复用同一 iframe 实例。
- */
+export interface NotificationClickedPayload {
+ sessionId?: string | null
+ title?: string
+ tag?: string
+}
+
export function Iframe({ iframeRef }: IframeProps) {
const { t } = useTranslation()
- const {
- serviceHealthy,
- startupStatusKey,
- showIframeError,
- iframeKey,
- iframeSrc,
- serviceUrl,
- } = useStore(store.harness)
- const { zoom_factor: zoomFactor } = useStore(store.setting)
-
+ const harness = useStore(store.harness)
+ const setting = useStore(store.setting)
const post = useIframePost(iframeRef)
+
+ // 转发 iframe 消息给 Tauri Rust 命令
useInvokeIframe(iframeRef)
+ // 将窗口可见性(最小化/隐藏/失焦)同步给 iframe,便于其暂停渲染
+ useSyncVisibility(iframeRef)
+
// 缩放真值 → WebView:显式传入真值,挂载时应用一次、之后真值变化才重应用;
// 平台能力判定(macOS 10.15 没有原生缩放)由 `useZoomFactor` 内部处理
- useZoomFactor(zoomFactor)
-
- /** 缩放动作只改真值(store 负责落盘),应用交给上面的 `useZoomFactor` */
- function applyZoom(action: ZoomAction) {
- store.setting.zoom_factor = nextZoomFactor(zoomFactor, action)
- }
-
- /** 壳层快捷键(焦点在导航栏等壳层元素时;iframe 内由注入脚本经缩放桥转发) */
- function handleZoomKeyDown(event: KeyboardEvent) {
- const action = zoomActionFromShortcut(event)
- if (!action)
- return
- event.preventDefault()
- applyZoom(action)
- }
+ useZoomFactor(setting.zoom_factor)
+ // 壳层快捷键(焦点在导航栏等壳层元素时;iframe 内由注入脚本经缩放桥转发)
useEventListener('keydown', handleZoomKeyDown, { capture: true })
+ // 系统通知点击 → 让 iframe 聚焦对应会话
+ useListen<NotificationClickedPayload>(
+ 'dsh-notification-clicked',
+ event => handleNotificationClicked(event.payload),
+ )
+
// iframe → 宿主:iframe 自身的桥共用一个监听器,按 `data.type` 分发
- useIframeMessage<IframeBridgeMessage>(iframeRef, (data, { origin }) => {
+ useIframeMessage<IframeBridgeMessage>(iframeRef, (data) => {
switch (data.type) {
// 原生通知:转发给 Tauri 命令弹出系统通知
case 'dsh://native-notification':
- void invoke('show_native_notification', {
- payload: {
- title: data.title ?? '',
- body: data.body ?? '',
- tag: data.tag ?? null,
- sessionId: data.sessionId ?? null,
- requireInteraction: Boolean(data.requireInteraction),
- },
- }).catch(error => console.error('[notification] show_native_notification failed:', error))
+ handleNativeNotification(data)
break
-
// 插件异常上报:写后端错误注册表,并刷新插件列表(「插件」面板据此展示 danger 与修复入口)
case 'dsh://plugin-error':
- if (!data.id || !data.error)
- break
- void invoke('report_plugin_error', {
- id: data.id,
- error: data.error,
- action: data.action ?? 'runtime',
- })
- .then(() => {
- void queryClient.invalidateQueries({ queryKey: queryKeys.plugins })
- })
- .catch(error => console.error('[plugin-error] report_plugin_error failed:', error))
+ handlePluginBoot(data)
break
-
// 剪贴板图片回退:读系统剪贴板并把 PNG data URL 回传
// (Linux/WebKitGTK 下 dsh iframe 的 paste 事件拿不到图片,走原生剪贴板通路)
- case 'dsh://clipboard-image:read': {
- if (!data.id)
- break
- const reqId = data.id
- function reply(dataUrl: string | null) {
- iframeRef.current?.contentWindow?.postMessage(
- { source: 'dsh-desktop-clipboard', id: reqId, data_url: dataUrl },
- origin,
- )
- }
- void invoke<{ data_url?: string } | null>('read_clipboard_image')
- .then(result => reply(result?.data_url ?? null))
- .catch((error) => {
- console.error('[clipboard-image] read_clipboard_image failed:', error)
- reply(null)
- })
+ case 'dsh://clipboard-image:read':
+ handleClipboardImageRead(data)
break
- }
-
// 插件 boot 状态:failed 携带官方失败页文本(如 web boot: 1 entry did not activate)
case 'dsh://plugin-boot:ready':
store.harness.markIframeBootReady()
@@ -163,96 +102,89 @@ export function Iframe({ iframeRef }: IframeProps) {
case 'dsh://plugin-boot:failed':
void store.harness.handleIframeBootFailure(data.detail)
break
-
// 缩放快捷键:跨源 iframe 内的 Ctrl/Cmd +/-/0 不会冒泡到壳层,由 dsh-tauri 插件的
- // `client/register/zoom-shortcut.ts` 在 iframe 内捕获后经父窗口桥转发到这里
case 'dsh://zoom-shortcut': {
- const action = zoomActionFromBridgeMessage(data)
- if (action)
- applyZoom(action)
+ handleZoomShortcut(data)
break
}
}
})
- // 系统通知点击 → 让 iframe 聚焦对应会话
- useListen<{ sessionId?: string | null, title?: string, tag?: string }>(
- 'dsh-notification-clicked',
- (event) => {
- const payload = event.payload
- post({
- type: 'dsh://focus-session',
- sessionId: payload.sessionId || undefined,
- title: payload.title || undefined,
- tag: payload.tag || undefined,
- })
- },
- )
+ function handleZoomKeyDown(event: KeyboardEvent) {
+ const action = zoomActionFromShortcut(event)
+ if (!action)
+ return
+ event.preventDefault()
+ setting.zoom(action)
+ }
- // 将窗口可见性(最小化/隐藏/失焦)同步给 iframe,便于其暂停渲染
- function syncVisibility() {
- void (async () => {
- try {
- const appWindow = getCurrentWindow()
- const [minimized, visible] = await Promise.all([
- appWindow.isMinimized(),
- appWindow.isVisible(),
- ])
- post({ type: 'dsh://visibility-state', hidden: minimized || !visible })
- }
- catch (error) {
- console.error('[notification] sync visibility failed:', error)
- }
- })()
+ function handleNativeNotification(data: IframeBridgeMessage) {
+ void invoke('show_native_notification', {
+ payload: {
+ title: data.title ?? '',
+ body: data.body ?? '',
+ tag: data.tag ?? null,
+ sessionId: data.sessionId ?? null,
+ requireInteraction: Boolean(data.requireInteraction),
+ },
+ }).catch(error => console.error('[notification] show_native_notification failed:', error))
}
- // 窗口焦点/尺寸变化时即时同步可见性(Tauri 窗口事件非 `listen`,保留 effect 承担注销)
- useEffect(() => {
- let disposed = false
- let unlisteners: Array<() => void> = []
- void (async () => {
- try {
- const appWindow = getCurrentWindow()
- syncVisibility()
- const unFocus = await appWindow.onFocusChanged(() => {
- void syncVisibility()
- })
- const unResized = await appWindow.onResized(() => {
- void syncVisibility()
- })
- // 订阅完成前若已卸载则立即释放,避免回调泄漏
- if (disposed) {
- unFocus()
- unResized()
- }
- else {
- unlisteners = [unFocus, unResized]
- }
- }
- catch (error) {
- console.error('[notification] visibility listeners failed:', error)
- }
- })()
- return () => {
- disposed = true
- unlisteners.forEach(fn => fn())
+ function handlePluginBoot(data: IframeBridgeMessage) {
+ if (!data.id || !data.error)
+ return
+ void invoke('report_plugin_error', {
+ id: data.id,
+ error: data.error,
+ action: data.action ?? 'runtime',
+ })
+ .then(() => {
+ void queryClient.invalidateQueries({ queryKey: queryKeys.plugins })
+ })
+ .catch(error => console.error('[plugin-error] report_plugin_error failed:', error))
+ }
+
+ function handleClipboardImageRead(data: IframeBridgeMessage) {
+ if (!data.id)
+ return
+ const reqId = data.id
+ function reply(dataUrl: string | null) {
+ post({ source: 'dsh://clipboard-image:reply', id: reqId, data_url: dataUrl })
}
- }, [])
+ void invoke<{ data_url?: string } | null>('read_clipboard_image')
+ .then(result => reply(result?.data_url ?? null))
+ .catch((error) => {
+ console.error('[clipboard-image] read_clipboard_image failed:', error)
+ reply(null)
+ })
+ }
- // 兜底轮询:覆盖监听不到的状态变化(如任务栏切换);主路径是窗口焦点/尺寸事件
- useIntervalFn(syncVisibility, VISIBILITY_POLL_INTERVAL)
+ function handleZoomShortcut(data: IframeBridgeMessage) {
+ const action = zoomActionFromBridgeMessage(data)
+ if (action)
+ setting.zoom(action)
+ }
+
+ function handleNotificationClicked(payload: NotificationClickedPayload) {
+ post({
+ type: 'dsh://focus-session',
+ sessionId: payload.sessionId || undefined,
+ title: payload.title || undefined,
+ tag: payload.tag || undefined,
+ })
+ }
return (
<div className="relative min-h-0 flex-1">
<If
- cond={serviceHealthy}
- else={<Loadable subtitle={t(startupStatusKey)} />}
+ cond={harness.serviceHealthy}
+ else={<Loadable subtitle={t(harness.startupStatusKey)} />}
>
<iframe
- key={iframeKey}
+ key={harness.iframeKey}
ref={iframeRef}
className="block h-full w-full border-none bg-load-bg"
- src={iframeSrc}
+ src={harness.iframeSrc}
allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; clipboard-read; clipboard-write; display-capture; document-domain; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; idle-detection; keyboard-map; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; speaker-selection; usb; web-share; xr-spatial-tracking"
sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals allow-downloads allow-storage-access-by-user-activation"
onLoad={store.harness.markIframeLoaded}
@@ -261,12 +193,12 @@ export function Iframe({ iframeRef }: IframeProps) {
/>
</If>
- <If cond={showIframeError}>
+ <If cond={harness.showIframeError}>
<div className="absolute inset-0 z-[1]">
<Loadable
icon={CircleExclamation}
title={t('ui.iframe_error')}
- errorMsg={t('ui.ensure_running', { url: serviceUrl })}
+ errorMsg={t('ui.ensure_running', { url: harness.serviceUrl })}
onRetry={store.harness.refreshIframe}
/>
</div>
diff --git a/src/store/modules/setting/constants.ts b/src/store/modules/setting/constants.ts
new file mode 100644
index 00000000..cd6623d7
--- /dev/null
+++ b/src/store/modules/setting/constants.ts
@@ -0,0 +1,8 @@
+/** 默认缩放比例(100%),与 Rust `default_zoom_factor` 一致 */
+export const ZOOM_FACTOR_DEFAULT = 1
+/** 缩放步长,与 Rust `ZOOM_FACTOR_STEP` 一致 */
+export const ZOOM_FACTOR_STEP = 0.1
+/** 缩放下限,与 Rust `ZOOM_FACTOR_MIN` 一致 */
+export const ZOOM_FACTOR_MIN = 0.5
+/** 缩放上限,与 Rust `ZOOM_FACTOR_MAX` 一致 */
+export const ZOOM_FACTOR_MAX = 2
diff --git a/src/store/modules/setting/index.ts b/src/store/modules/setting/index.ts
index 113e96be..99039d90 100644
--- a/src/store/modules/setting/index.ts
+++ b/src/store/modules/setting/index.ts
@@ -1,2 +1 @@
export { setting } from './store'
-export type { AppSetting, AppSettingUpdate } from './types'
diff --git a/src/store/modules/setting/store.ts b/src/store/modules/setting/store.ts
index ff32e2a5..4fb026cb 100644
--- a/src/store/modules/setting/store.ts
+++ b/src/store/modules/setting/store.ts
@@ -1,7 +1,11 @@
+import type { AppSettingUpdate, ZoomAction } from './types'
+import { invoke } from '@tauri-apps/api/core'
import { listen } from '@tauri-apps/api/event'
import { defineStore } from 'valtio-define'
import { persist } from 'valtio-define/plugins/persist'
import { storage } from '@/config/storage'
+import { ZOOM_FACTOR_STEP } from './constants'
+import { normalizeZoomFactor } from './utils'
export const setting = defineStore({
state: () => ({
@@ -15,6 +19,19 @@ export const setting = defineStore({
backup_include_credentials: false,
language: null as string | null,
}),
+ actions: {
+ update(update: AppSettingUpdate) {
+ return invoke('update_app_config', { ...update })
+ },
+ zoom(action: ZoomAction) {
+ if (action === 'reset') {
+ this.zoom_factor = 1
+ return
+ }
+ const delta = action === 'increase' ? ZOOM_FACTOR_STEP : -ZOOM_FACTOR_STEP
+ this.zoom_factor = normalizeZoomFactor(this.zoom_factor + delta)
+ },
+ },
persist: {
key: 'setting',
storage,
diff --git a/src/store/modules/setting/types.ts b/src/store/modules/setting/types/index.ts
similarity index 52%
rename from src/store/modules/setting/types.ts
rename to src/store/modules/setting/types/index.ts
index b176ad89..a51d97cf 100644
--- a/src/store/modules/setting/types.ts
+++ b/src/store/modules/setting/types/index.ts
@@ -1,9 +1,3 @@
-/**
- * 桌面端设置中**前端关心**的子集(字段名与 Rust `config::Setting` 一致,snake_case 直通)。
- *
- * 只镜像外壳真正消费的字段:档案、核心、桌宠、迁移标记等各有专用命令与查询,
- * 一并塞进来只会制造第二份真相。
- */
export interface AppSetting {
/** 依赖是否已安装(boot 流程据此决定是否走安装与更新检查) */
installed: boolean
@@ -16,11 +10,6 @@ export interface AppSetting {
backup_include_credentials: boolean
}
-/**
- * `update_app_config` 的可写字段(camelCase,与 Rust 命令参数一一对应)。
- *
- * 语义是「部分更新」:未传的字段由后端保持原值。
- */
export interface AppSettingUpdate {
port?: number
autoStart?: boolean
@@ -29,3 +18,5 @@ export interface AppSettingUpdate {
backupRetentionCount?: number
backupIncludeCredentials?: boolean
}
+
+export type ZoomAction = 'increase' | 'decrease' | 'reset'
diff --git a/src/store/modules/setting/utils/index.ts b/src/store/modules/setting/utils/index.ts
new file mode 100644
index 00000000..ff613290
--- /dev/null
+++ b/src/store/modules/setting/utils/index.ts
@@ -0,0 +1,9 @@
+import { ZOOM_FACTOR_DEFAULT, ZOOM_FACTOR_MAX, ZOOM_FACTOR_MIN, ZOOM_FACTOR_STEP } from '../constants'
+
+export function normalizeZoomFactor(value: number): number {
+ if (!Number.isFinite(value))
+ return ZOOM_FACTOR_DEFAULT
+ const grid = 1 / ZOOM_FACTOR_STEP
+ const clamped = Math.min(Math.max(value, ZOOM_FACTOR_MIN), ZOOM_FACTOR_MAX)
+ return Math.round(clamped * grid) / grid
+}
diff --git a/src/ui/config/components/close-action.tsx b/src/ui/config/components/close-action.tsx
index 8711ddc9..737a2716 100644
--- a/src/ui/config/components/close-action.tsx
+++ b/src/ui/config/components/close-action.tsx
@@ -1,7 +1,5 @@
-import type { AppSettingUpdate } from '@/store/modules/setting'
import { Description, ListBox, Select } from '@heroui/react'
import { useMutation } from '@tanstack/react-query'
-import { invoke } from '@tauri-apps/api/core'
import { useTranslation } from 'react-i18next'
import { useStore } from 'valtio-define'
import { store } from '@/store'
@@ -27,7 +25,7 @@ export function ConfigCloseAction() {
const { mutate: setCloseAction, isPending } = useMutation({
mutationFn: (next: string) =>
// `satisfies` 用共享类型守住 camelCase 契约:字段名写错时后端会静默忽略
- invoke('update_app_config', { closeAction: normalizeCloseAction(next) } satisfies AppSettingUpdate),
+ store.setting.update({ closeAction: normalizeCloseAction(next) }),
onError: (error: unknown) => {
console.error('[ConfigCloseAction] update failed:', error)
toast(t('messages.close_action_failed'), { variant: 'danger' })
diff --git a/src/ui/config/debug.tsx b/src/ui/config/debug.tsx
index e43ddf03..e52c140a 100644
--- a/src/ui/config/debug.tsx
+++ b/src/ui/config/debug.tsx
@@ -1,4 +1,3 @@
-import type { AppSettingUpdate } from '@/store/modules/setting'
import { ArrowRotateRight, ArrowUpRightFromSquare, ChevronRight, Copy, Folder, Power, TrashBin } from '@gravity-ui/icons'
import { Button, Chip, Description, Input, Link, ListBox, Select, Spinner, Surface, Switch } from '@heroui/react'
import { useMutation, useQuery } from '@tanstack/react-query'
@@ -111,7 +110,7 @@ export function ConfigDebug() {
const { mutate: onToggleCliLink } = useMutation({
mutationFn: async (enabled: boolean) => {
// 命令会先建/删 shim 与 PATH 再落盘,前端只改 store 不会产生这些副作用
- await invoke('update_app_config', { cliLinkEnabled: enabled } satisfies AppSettingUpdate)
+ await store.setting.update({ cliLinkEnabled: enabled })
await refreshCliStatus()
},
onError: (err: unknown) => {
@@ -146,7 +145,7 @@ export function ConfigDebug() {
throw new Error('PORT_INVALID')
}
// 后端会同时记录 manual_port(端口避让后回落到用户选择,issue #91)
- await invoke('update_app_config', { port } satisfies AppSettingUpdate)
+ await store.setting.update({ port })
const key = toast(t('messages.port_changed'), {
variant: 'accent',
description: t('messages.port_restart_hint'),
diff --git a/src/utils/zoom.ts b/src/utils/zoom.ts
index b6019726..efe0d102 100644
--- a/src/utils/zoom.ts
+++ b/src/utils/zoom.ts
@@ -60,13 +60,10 @@ export function zoomLevelFromFactor(factor: number): number {
/** 默认缩放比例(100%),与 Rust `default_zoom_factor` 一致 */
export const ZOOM_FACTOR_DEFAULT = 1
-
/** 缩放步长,与 Rust `ZOOM_FACTOR_STEP` 一致 */
export const ZOOM_FACTOR_STEP = 0.1
-
/** 缩放下限,与 Rust `ZOOM_FACTOR_MIN` 一致 */
export const ZOOM_FACTOR_MIN = 0.5
-
/** 缩放上限,与 Rust `ZOOM_FACTOR_MAX` 一致 */
export const ZOOM_FACTOR_MAX = 2
@@ -85,11 +82,3 @@ export function normalizeZoomFactor(value: number): number {
const clamped = Math.min(Math.max(value, ZOOM_FACTOR_MIN), ZOOM_FACTOR_MAX)
return Math.round(clamped * grid) / grid
}
-
-/** 按缩放动作计算下一档比例(increase/decrease 走 0.1 步长,reset 回 100%) */
-export function nextZoomFactor(current: number, action: ZoomAction): number {
- if (action === 'reset')
- return ZOOM_FACTOR_DEFAULT
- const delta = action === 'increase' ? ZOOM_FACTOR_STEP : -ZOOM_FACTOR_STEP
- return normalizeZoomFactor(current + delta)
-}