Files
Thing/src/lib/constants.ts
T

194 lines
10 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 全局常量集中定义。
* 窗口 label / Tauri 事件名 / localStorage 存储键,避免魔法字符串散布各处。
* 与 Rust 侧 `src-tauri/src/constants.rs` 保持对应。
*/
/** 窗口 label(对应 Rust constants::windows 与 capabilities/*.json) */
export const WINDOWS = {
main: 'main',
osdOverlay: 'osd-overlay',
screenshotOverlay: 'screenshot-overlay',
screenshotPin: 'screenshot-pin',
/** 常驻截图编辑器窗口(隐藏复用,打开只 show 不重建 WebView) */
screenshotEditor: 'screenshot-editor',
/** 滚动截图控制窗 */
screenshotScroll: 'screenshot-scroll',
/** 单文件一次性下载窗口前缀,实际 label = `${downloadWindow}-<taskId>` */
downloadWindow: 'download-window',
/** 取词翻译悬浮窗(非激活显示,由 Rust 预创建) */
translatePopup: 'translate-popup',
/** 单个终端独立窗口,实际 label = `terminal-window-<sessionId>` */
terminalWindow: 'terminal-window',
/**
* dsh 模块的 Web UI 独立窗口。
* 内容为远端 `http://127.0.0.1:<port>`,因此**不登记 capability**——
* 远端页面不应获得任何 Tauri 权限(Windows 平台上 label 未命中任何 capability
* 时,webview 仍可正常加载与交互,只是拿不到 IPC)。
*/
dshWeb: 'dsh-web',
/** 笔记独立窗口前缀,实际 label = `${notesWindow}-<n>`(可多开) */
notesWindow: 'notes-window',
} as const
/** Tauri 事件名(前端 emit / listen 与 Rust constants::events 对应) */
export const EVENTS = {
// 托盘菜单
trayMenuShow: 'tray-menu-show',
trayMenuStateUpdated: 'tray-menu-state-updated',
trayToggleOsd: 'tray:toggle-osd',
trayNewDownload: 'tray:new-download',
trayOpenSettings: 'tray:open-settings',
// 剪贴板
clipboardChanged: 'clipboard-changed',
clipboardPopupShow: 'clipboard-popup-show',
clipboardPopupHide: 'clipboard-popup-hide',
clipboardPreviewShow: 'clipboard-preview-show',
clipboardPreviewHide: 'clipboard-preview-hide',
// 鼠标进入/离开独立预览窗(弹窗据此决定是否延迟隐藏预览,便于点击复制/放大)
clipboardPreviewEnter: 'clipboard-preview-enter',
clipboardPreviewLeave: 'clipboard-preview-leave',
// 快速面板
quickpanelShow: 'quickpanel-show',
quickpanelHide: 'quickpanel-hide',
quickpanelExecuteCommand: 'quickpanel-execute-command',
quickpanelExtractProgress: 'quickpanel-extract-progress',
// 文件索引构建完成(闲时自动建立/重建、手动构建)
quickpanelIndexUpdated: 'quickpanel-index-updated',
// 截图
screenshotBegin: 'screenshot-begin',
screenshotOverlayReady: 'screenshot-overlay-ready',
/** 覆盖层握手请求:主窗口每次发起截图前询问覆盖层是否已注册好 begin 监听(覆盖层以 screenshotOverlayReady 应答) */
screenshotOverlayPing: 'screenshot-overlay-ping',
screenshotShortcut: 'screenshot-shortcut',
screenshotPinShortcut: 'screenshot-pin-shortcut',
screenshotPinReady: 'screenshot-pin-ready',
/** 贴图窗口握手请求(同覆盖层):贴图窗口以 screenshotPinReady 应答 */
screenshotPinPing: 'screenshot-pin-ping',
screenshotPinShow: 'screenshot-pin-show',
screenshotExported: 'screenshot-exported',
/** 滚动截图会话:实时进度 { width, height, auto } */
scrollProgress: 'screenshot-scroll-progress',
/** 滚动截图会话:完成并导出(Rust 已把 PNG 原始字节写入编辑器图片槽,事件只带 { width, height }) */
scrollComplete: 'screenshot-scroll-complete',
/** 滚动截图会话:已取消 */
scrollCancelled: 'screenshot-scroll-cancelled',
/** 滚动截图完成:打开截图编辑器(编辑/裁剪后保存才进历史) */
scrollToEditor: 'screenshot-scroll-to-editor',
/** 常驻编辑器窗口挂载完成(store 等待后下发加载事件) */
screenshotEditorReady: 'screenshot-editor-ready',
/** 编辑器握手请求(同覆盖层):编辑器以 screenshotEditorReady 应答 */
screenshotEditorPing: 'screenshot-editor-ping',
/** 通知常驻编辑器窗口加载编辑器图片槽中的新图(raw IPC 取出) */
screenshotEditorLoad: 'screenshot-editor-load',
// 内核安装进度
kernelInstallProgress: 'kernel-install-progress',
// 翻译:取词悬浮窗显示(负载见 Rust translate::popup::PopupPayload)/ 隐藏
translatePopupShow: 'translate-popup-show',
translatePopupHide: 'translate-popup-hide',
// 翻译:流式输出(失败经 start 的 Promise reject,不走事件)
translateStreamChunk: 'translate-stream-chunk',
translateStreamDone: 'translate-stream-done',
translateStreamError: 'translate-stream-error',
// 后端自动切换节点完成(后台执行,刷新节点列表并提示)
proxyAutoSwitch: 'proxy-auto-switch',
// 应用更新进度
updateProgress: 'update-progress',
// 终端:会话输出批次(按 8~16ms 窗口聚合,前端用 seq 校验连续性)
terminalOutput: 'terminal-output',
/** 终端:会话结束 */
terminalExit: 'terminal-exit',
/** 终端:会话状态变更(负载为 SessionInfo) */
terminalState: 'terminal-state',
/** 终端:工作目录变化(OSC 7 hook 上报) */
terminalCwd: 'terminal-cwd',
/** 终端:SSH 主机密钥需用户确认(阻塞式,握手在等待回传) */
terminalHostKeyPrompt: 'terminal-host-key-prompt',
/** 终端:SFTP 传输进度(上传/下载,节流 200ms 推送一次) */
terminalTransferProgress: 'terminal-transfer-progress',
/** 终端:请求对「关闭仍在运行的会话」二次确认 */
terminalConfirmClose: 'terminal-confirm-close',
/** 终端:设置已保存(无负载)。各窗口据此重读设置,实现跨窗口同步 */
terminalSettings: 'terminal-settings',
// 监控 OSD
osdStateUpdate: 'osd-state-update',
/** OSD 数据通道:仅推送显示项 key→value 映射 + 网速(高频,每秒) */
osdDataUpdate: 'osd-data-update',
/** OSD 窗口挂载后请求主窗口补发配置+数据(防止错过创建时的首推) */
osdConfigRequest: 'osd-config-request',
osdContentSize: 'osd-content-size',
osdSystemUiActive: 'osd-system-ui-active',
osdSystemUiInactive: 'osd-system-ui-inactive',
/** 前台出现全屏应用(游戏):OSD 应隐藏以避免游戏掉帧 */
osdGameActive: 'osd-game-active',
/** 全屏应用退出前台:OSD 可恢复显示 */
osdGameInactive: 'osd-game-inactive',
osdStartDrag: 'osd-start-drag',
osdEndDrag: 'osd-end-drag',
monitorReady: 'monitor-ready',
monitorLoading: 'monitor-loading',
monitorDisconnected: 'monitor-disconnected',
monitorError: 'monitor-error',
monitorData: 'monitor-data',
monitorNetwork: 'monitor-network',
// 音乐:Rust 侧播放引擎(music/audio)。曲目自然播完(缓冲也放完)后发出,无负载
musicAudioEnded: 'music-audio-ended',
/** 音乐:Rust 侧播放失败(音源打不开 / 解码失败 / 输出设备异常),负载为错误文本 */
musicAudioError: 'music-audio-error',
// 其他
processStatusChanged: 'process-status-changed',
downloadAdded: 'download-added',
/** 任务被删除(浏览器扩展通过 HTTP API 删除任务时发出,前端据此刷新任务列表) */
downloadRemoved: 'download-removed',
/** 浏览器扩展通过 HTTP API 新增下载(负载 { id },前端据以为该任务创建专属下载窗口) */
downloadExtensionAdded: 'download-extension-added',
// dsh 模块
/** 安装/下载进度(负载见 src/types/dsh.ts 的 DshInstallProgress) */
dshInstallProgress: 'dsh-install-progress',
/** 服务进程状态(负载见 src/types/dsh.ts 的 DshServerStatus) */
dshServerState: 'dsh-server-state',
/** 全局快捷键按下:打开 dsh 独立窗口(无负载) */
dshOpenWindow: 'dsh-open-window',
/** 笔记:设置已保存(无负载)。各窗口据此重读设置,实现跨窗口同步 */
notesSettings: 'notes-settings',
/** 笔记:库内容已变更(新建/保存/重命名/删除/切换库根,无负载) */
notesLibraryChanged: 'notes-library-changed',
/** 笔记:库内文件在应用外被改动(负载见 src/types/notes.ts 的 NoteFileEvent) */
notesFileChanged: 'notes-file-changed',
/** 笔记:WebDAV 同步进度(负载见 src/types/notes.ts 的 SyncProgress) */
notesSyncProgress: 'notes-sync-progress',
/** 笔记:全局快捷键「新建笔记」被按下(无负载;主窗口据此打开新建对话框) */
notesNewNote: 'notes-new-note',
/** 笔记:全局快捷键「打开编辑器」被按下(无负载) */
notesOpenEditor: 'notes-open-editor',
/** 笔记:需要打开一个磁盘文件(负载 `{ path }`;来自文件关联 / 命令行) */
notesOpenFile: 'notes-open-file',
} as const
/** localStorage 存储键 */
export const STORAGE_KEYS = {
appSettings: 'thing_app_settings',
lastModule: 'thing_last_module',
quickpanelCommands: 'thing_quickpanel_commands',
quickpanelSettings: 'thing_quickpanel_settings',
quickpanelHistory: 'thing_quickpanel_history',
quickpanelHistoryItems: 'thing_quickpanel_history_items',
quickpanelPwdHistory: 'thing_quickpanel_pwd_history',
quickpanelPwdFavs: 'thing_quickpanel_pwd_favs',
quickpanelRenameMatchHistory: 'thing_quickpanel_rename_match_history',
quickpanelRenameMatchFavs: 'thing_quickpanel_rename_match_favs',
quickpanelRenameReplaceHistory: 'thing_quickpanel_rename_replace_history',
quickpanelRenameReplaceFavs: 'thing_quickpanel_rename_replace_favs',
quickpanelDeleteFilterHistory: 'thing_quickpanel_delete_filter_history',
quickpanelDeleteFilterFavs: 'thing_quickpanel_delete_filter_favs',
currencyRates: 'thing_quickpanel_currency_rates',
monitorOsdConfig: 'thing_monitor_osd_config',
/** 关闭"自动启动监控内核"时暂存的 OSD 开关状态(开启自动启动时据此恢复) */
monitorOsdPending: 'thing_monitor_osd_pending',
monitorOverviewCards: 'thing_monitor_overview_cards',
screenshotHistory: 'thing_screenshot_history',
screenshotPinIndex: 'thing_screenshot_pin_index',
/** 笔记模块:最近打开(`{ relPath, name, at }[]`) */
notesRecent: 'thing_notes_recent',
} as const