Files
Thing/src/lib/constants.ts
T

125 lines
5.9 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',
} 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',
screenshotShortcut: 'screenshot-shortcut',
screenshotPinShortcut: 'screenshot-pin-shortcut',
screenshotPinReady: 'screenshot-pin-ready',
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',
/** 通知常驻编辑器窗口加载编辑器图片槽中的新图(raw IPC 取出) */
screenshotEditorLoad: 'screenshot-editor-load',
// 内核安装进度
kernelInstallProgress: 'kernel-install-progress',
// 后端自动切换节点完成(后台执行,刷新节点列表并提示)
proxyAutoSwitch: 'proxy-auto-switch',
// 应用更新进度
updateProgress: 'update-progress',
// 监控 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',
// 其他
processStatusChanged: 'process-status-changed',
downloadAdded: 'download-added',
/** 任务被删除(浏览器扩展通过 HTTP API 删除任务时发出,前端据此刷新任务列表) */
downloadRemoved: 'download-removed',
/** 浏览器扩展通过 HTTP API 新增下载(负载 { id },前端据以为该任务创建专属下载窗口) */
downloadExtensionAdded: 'download-extension-added',
} 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',
} as const