Skip to content

refactor: 使用 native getSelectedContent 替代剪贴板轮询取词#525

Merged
lzx8589561 merged 2 commits into
ZToolsCenter:mainfrom
Particaly:refactor/use-native-get-selected-content
Jun 3, 2026
Merged

refactor: 使用 native getSelectedContent 替代剪贴板轮询取词#525
lzx8589561 merged 2 commits into
ZToolsCenter:mainfrom
Particaly:refactor/use-native-get-selected-content

Conversation

@Particaly

Copy link
Copy Markdown
Collaborator

关联 native 相关功能 #9

  • 移除超时常量 CLIPBOARD_COPY_WAIT_TIMEOUT_MS、KEY_RELEASE_WAIT_TIMEOUT_MS、GLOBAL_SHORTCUT_COOLDOWN_MS
  • 简化 captureSelectedTextContext 方法,直接调用 native getSelectedContent()
  • 移除防抖逻辑,native 层自动处理按键释放和剪贴板暂停
  • 支持获取文本、图片、文件三种类型的选中内容
  • 移除对 clipboardManager 的依赖
  • 新增 WindowManager.getSelectedContent 类型定义

- 移除超时常量 CLIPBOARD_COPY_WAIT_TIMEOUT_MS、KEY_RELEASE_WAIT_TIMEOUT_MS、GLOBAL_SHORTCUT_COOLDOWN_MS
- 简化 captureSelectedTextContext 方法,直接调用 native getSelectedContent()
- 移除防抖逻辑,native 层自动处理按键释放和剪贴板暂停
- 支持获取文本、图片、文件三种类型的选中内容
- 移除对 clipboardManager 的依赖
- 新增 WindowManager.getSelectedContent 类型定义

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the manual clipboard-delay and key-release waiting logic in settings.ts with a new native method, NativeWindowManager.getSelectedContent(), which retrieves selected text, images, or files directly. Feedback on these changes suggests adding a defensive check to ensure the returned content is a valid array, dynamically determining if captured file paths are directories or files using fs.statSync (and importing fs), and using a discriminated union type for getSelectedContent to improve type safety.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main/api/renderer/settings.ts
Comment thread src/main/api/renderer/settings.ts Outdated
Comment thread src/main/api/renderer/settings.ts
Comment thread src/main/core/native/index.ts Outdated
Comment thread src/main/core/native/index.ts Outdated
- 使用 discriminated union 类型提供更强的类型安全性和自动类型收窄
- 添加防御性检查,确保 contents 是有效数组后再访问属性
- 使用 fs.statSync 动态判断文件/目录类型,避免硬编码
- 导入 fs 模块以支持文件状态检查
- 添加错误处理,文件读取失败时使用默认值
@lzx8589561 lzx8589561 merged commit eac2a4c into ZToolsCenter:main Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants