fix(贴图): 修复原生命令运行时失败时无法回退到 WebView 版的问题#367
Open
ExLei wants to merge 2 commits into
Hidden character warning
The head ref may contain hidden characters: "fix/\u8d34\u56fe\u529f\u80fd\u56de\u9000\u4fee\u590d"
Open
Conversation
去除基于错误字符串匹配的回退条件(includes("not found") ||
includes("Command")),改为原生命令任何运行时失败都回退到
Tauri WebView 版并保留错误日志。行为与 Rust 侧 tray/menu.rs
一致。双重失败时合并错误信息而非丢弃原生错误上下文。
修改:
- clipboard.js: pinImageToScreen() 去除条件判断,始终回退
- contextMenu.js: PreviewController.bind() 预览回退同样修复
pin-image 操作调用 pinImageToScreen() 之前未捕获异常, 失败时用户看不到任何反馈。加入 try/catch + toast.error 给用户友好提示。
Contributor
Author
|
@mosheng1 应该不史了 来看看吧( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
修复前端原生 GPU 图像功能的回退逻辑缺陷:去除基于错误字符串匹配的条件判断,改为无条件回退。
虽然只是健壮性修复(实际连回退逻辑都没触发就是了(
问题描述
v0.4.0 官方发行版中,贴图功能无法调用。入口(右键菜单「贴到屏幕」、托盘菜单「贴图」)均无响应,无窗口弹出,无错误提示。
分析
实际测试中发现完整链路存在两层问题。
第一层:gpu-image-viewer 侧窗口不可见但未报错
完整版中调用贴图功能,前端收到成功返回值,
toast.success提示「图片已贴到屏幕」,但实际没有贴图窗口出现。此时前端未进入catch分支,回退逻辑未触发。第二层:前端回退逻辑只匹配特定错误字符串
clipboard.js:pinImageToScreen()和contextMenu.js:PreviewController.bind()中的回退条件:此条件只命中「命令未注册」场景(社区编译版),未命中「命令已注册但运行时失败」场景(官方发行版):
"Command ... not found""创建原生贴图窗口失败: WebGPU adapter not available""GPU adapter initialization failed: DXGI_ERROR_DEVICE_REMOVED"官方发行版中
gpu-image-viewer插件已编译进应用,create_native_pin_from_file/show_native_image_preview命令已注册。运行时失败时 Rust 命令返回的Err(String)不包含"not found"或"Command"关键词,回退条件不满足,pin_image_from_file永远不会被调用。Rust 侧
src-tauri/src/windows/tray/menu.rs:272-283在同一提交(d95a542e)中已实现无条件回退(if let Err(e) = create_native_pin_from_file(…) { eprintln!(…); fallback }),前端两处是此一致模式的仅剩遗留。两层问题叠加
本 PR 修复第二层。
复现方法
社区版原生命令不存在,无法直接复现。在前端注入 mock 错误模拟 GPU 运行时失败:
错误不含
"not found"或"Command"。复现结果
修改文件
src/shared/api/clipboard.js—pinImageToScreen()回退逻辑,补日志,双重失败时合并错误信息src/plugins/context_menu/contextMenu.js—PreviewController.bind()预览回退逻辑,WebView 版失败时补日志src/shared/utils/contextMenu.js—handleContentTypeActions()调用方加 try/catch + toast.error验证
git grep确认错误字符串匹配模式(includes('not found') || includes('Command'))已从 JS 代码库完全消除