Skip to content

feat: pin#98

Open
Windsland52 wants to merge 5 commits intoMistEO:mainfrom
Windsland52:feat/pin
Open

feat: pin#98
Windsland52 wants to merge 5 commits intoMistEO:mainfrom
Windsland52:feat/pin

Conversation

@Windsland52
Copy link
Contributor

@Windsland52 Windsland52 commented Mar 2, 2026

Summary by Sourcery

在自定义的 Tauri 标题栏中添加一个“始终置顶”的固定控制按钮,并将其与窗口状态和控制器行为集成。

新功能:

  • 在 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:

  • Introduce an always-on-top pin toggle button in the Tauri window title bar.

Enhancements:

  • Track and initialize the window's always-on-top state via a shared window reference reused by all window control actions.
  • Disable and auto-clear the always-on-top state when using incompatible foreground screenshot methods based on the active controller configuration.
  • Add localized labels for pin, unpin, and pin-disabled tooltips across all supported languages.

新功能:

  • 在 Tauri 窗口的标题栏中新增一个始终置顶的固定切换按钮。

增强内容:

  • 在现有窗口状态的基础上,初始化并跟踪窗口的始终置顶状态。
  • 为所有受支持的语言环境添加窗口控件的“固定”和“取消固定”本地化标签。
Original summary in English

Summary by Sourcery

在自定义的 Tauri 标题栏中添加一个“始终置顶”的固定控制按钮,并将其与窗口状态和控制器行为集成。

新功能:

  • 在 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:

  • Introduce an always-on-top pin toggle button in the Tauri window title bar.

Enhancements:

  • Track and initialize the window's always-on-top state via a shared window reference reused by all window control actions.
  • Disable and auto-clear the always-on-top state when using incompatible foreground screenshot methods based on the active controller configuration.
  • Add localized labels for pin, unpin, and pin-disabled tooltips across all supported languages.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Windsland52 Windsland52 marked this pull request as draft March 2, 2026 11:19
@Windsland52 Windsland52 marked this pull request as ready for review March 2, 2026 14:54
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题,并给了一些总体反馈:

  • 目前只在 platform === 'windows' 的 effect 里初始化 windowRef,会导致在 macOS/Linux 的 Tauri 构建中,最小化/最大化/关闭按钮(以及 pin)都变成空操作;建议在 Tauri 环境下无条件初始化 windowRef,这样这些窗口控制在各平台都能正常工作。
  • isPinDisableduseMemo 中的 foregroundMethods Set 会在每次渲染时重新创建;把它移动到模块级常量(或者至少移出这个 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>

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进之后的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant