Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我在这里给出了一些总体反馈:
- 在
TitleBar中,你在 effect 里(为了appWindow)和在handleToggleAlwaysOnTop中(为了getCurrentWindow)都对@tauri-apps/api/window做了动态导入;可以考虑复用同一个窗口实例(例如appWindow),以避免重复导入和潜在的不一致问题。 - 窗口控制按钮上方的注释写的是它们“仅限 Windows/Linux”,但新的固定(pin)按钮目前只通过
isTauri()而不是platform进行限制;可以考虑让平台判断条件和现有注释保持一致,或者更新注释以反映实际行为。 - 在
handleToggleAlwaysOnTop中,你可以在等待setAlwaysOnTop之前乐观地更新isAlwaysOnTop(并在出错时回滚),这样在切换固定状态时,UI 会显得更灵敏。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- In `TitleBar`, you’re dynamically importing `@tauri-apps/api/window` both in the effect (for `appWindow`) and in `handleToggleAlwaysOnTop` (for `getCurrentWindow`); consider reusing the same window instance (e.g., `appWindow`) to avoid redundant imports and potential inconsistencies.
- The comment above the window control buttons says they are "Windows/Linux only", but the new pin button is still gated only by `isTauri()` and not by `platform`; consider aligning the platform condition with the existing comment or updating the comment to reflect the actual behavior.
- In `handleToggleAlwaysOnTop`, you could optimistically update `isAlwaysOnTop` before awaiting `setAlwaysOnTop` (and revert on error) to keep the UI feeling more responsive when toggling the pin state.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- In
TitleBar, you’re dynamically importing@tauri-apps/api/windowboth in the effect (forappWindow) and inhandleToggleAlwaysOnTop(forgetCurrentWindow); consider reusing the same window instance (e.g.,appWindow) to avoid redundant imports and potential inconsistencies. - The comment above the window control buttons says they are "Windows/Linux only", but the new pin button is still gated only by
isTauri()and not byplatform; consider aligning the platform condition with the existing comment or updating the comment to reflect the actual behavior. - In
handleToggleAlwaysOnTop, you could optimistically updateisAlwaysOnTopbefore awaitingsetAlwaysOnTop(and revert on error) to keep the UI feeling more responsive when toggling the pin state.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `TitleBar`, you’re dynamically importing `@tauri-apps/api/window` both in the effect (for `appWindow`) and in `handleToggleAlwaysOnTop` (for `getCurrentWindow`); consider reusing the same window instance (e.g., `appWindow`) to avoid redundant imports and potential inconsistencies.
- The comment above the window control buttons says they are "Windows/Linux only", but the new pin button is still gated only by `isTauri()` and not by `platform`; consider aligning the platform condition with the existing comment or updating the comment to reflect the actual behavior.
- In `handleToggleAlwaysOnTop`, you could optimistically update `isAlwaysOnTop` before awaiting `setAlwaysOnTop` (and revert on error) to keep the UI feeling more responsive when toggling the pin state.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给了一些总体反馈:
- 目前只在
platform === 'windows'的 effect 里初始化windowRef,会导致在 macOS/Linux 的 Tauri 构建中,最小化/最大化/关闭按钮(以及 pin)都变成空操作;建议在 Tauri 环境下无条件初始化windowRef,这样这些窗口控制在各平台都能正常工作。 isPinDisabled的useMemo中的foregroundMethodsSet会在每次渲染时重新创建;把它移动到模块级常量(或者至少移出这个 hook)可以避免每次渲染时不必要的分配和比较。
供 AI Agents 使用的提示词
Please address the comments from this code review:
## Overall Comments
- By only initializing `windowRef` inside the `platform === 'windows'` effect, the minimize/maximize/close buttons (and pin) will no-op on macOS/Linux Tauri builds; consider initializing `windowRef` unconditionally for Tauri so these controls continue to work cross‑platform.
- The `foregroundMethods` `Set` in the `isPinDisabled` `useMemo` is recreated on every render; moving it to a module-level constant (or at least outside the hook) will avoid unnecessary allocations and comparisons on each render.
## Individual Comments
### Comment 1
<location path="src/components/TitleBar.tsx" line_range="75-77" />
<code_context>
+ }
+ }, [isPinDisabled, isAlwaysOnTop]);
+
// 监听窗口最大化状态变化(仅 Windows,用于切换最大化/还原按钮图标)
useEffect(() => {
if (!isTauri() || platform !== 'windows') return;
</code_context>
<issue_to_address>
**issue (bug_risk):** windowRef is never initialized on non-Windows platforms, breaking window controls there.
`windowRef.current` is only set in the `platform === 'windows'` effect, but the Tauri window controls render whenever `isTauri()` is true (including Linux/macOS). Since the handlers now early-return when `windowRef.current` is null, minimize/maximize/close stop working on non-Windows platforms, whereas the previous `getCurrentWindow()` calls worked everywhere.
Either initialize `windowRef.current` in a platform-agnostic effect whenever `isTauri()` is true, or restrict rendering of the window controls to platforms where `windowRef` is guaranteed to be set, so Linux/macOS behavior doesn’t regress.
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进之后的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- By only initializing
windowRefinside theplatform === 'windows'effect, the minimize/maximize/close buttons (and pin) will no-op on macOS/Linux Tauri builds; consider initializingwindowRefunconditionally for Tauri so these controls continue to work cross‑platform. - The
foregroundMethodsSetin theisPinDisableduseMemois recreated on every render; moving it to a module-level constant (or at least outside the hook) will avoid unnecessary allocations and comparisons on each render.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- By only initializing `windowRef` inside the `platform === 'windows'` effect, the minimize/maximize/close buttons (and pin) will no-op on macOS/Linux Tauri builds; consider initializing `windowRef` unconditionally for Tauri so these controls continue to work cross‑platform.
- The `foregroundMethods` `Set` in the `isPinDisabled` `useMemo` is recreated on every render; moving it to a module-level constant (or at least outside the hook) will avoid unnecessary allocations and comparisons on each render.
## Individual Comments
### Comment 1
<location path="src/components/TitleBar.tsx" line_range="75-77" />
<code_context>
+ }
+ }, [isPinDisabled, isAlwaysOnTop]);
+
// 监听窗口最大化状态变化(仅 Windows,用于切换最大化/还原按钮图标)
useEffect(() => {
if (!isTauri() || platform !== 'windows') return;
</code_context>
<issue_to_address>
**issue (bug_risk):** windowRef is never initialized on non-Windows platforms, breaking window controls there.
`windowRef.current` is only set in the `platform === 'windows'` effect, but the Tauri window controls render whenever `isTauri()` is true (including Linux/macOS). Since the handlers now early-return when `windowRef.current` is null, minimize/maximize/close stop working on non-Windows platforms, whereas the previous `getCurrentWindow()` calls worked everywhere.
Either initialize `windowRef.current` in a platform-agnostic effect whenever `isTauri()` is true, or restrict rendering of the window controls to platforms where `windowRef` is guaranteed to be set, so Linux/macOS behavior doesn’t regress.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary by Sourcery
在自定义的 Tauri 标题栏中添加一个“始终置顶”的固定控制按钮,并将其与窗口状态和控制器行为集成。
新功能:
改进:
Original summary in English
Summary by Sourcery
Add an always-on-top pin control to the custom Tauri title bar while integrating it with window state and controller behavior.
New Features:
Enhancements:
新功能:
增强内容:
Original summary in English
Summary by Sourcery
在自定义的 Tauri 标题栏中添加一个“始终置顶”的固定控制按钮,并将其与窗口状态和控制器行为集成。
新功能:
改进:
Original summary in English
Summary by Sourcery
Add an always-on-top pin control to the custom Tauri title bar while integrating it with window state and controller behavior.
New Features:
Enhancements: