Skip to content

fix(wework): restore main window close flow - #2326

Merged
qdaxb merged 1 commit into
mainfrom
fix/wework-main-window-close
Jul 30, 2026
Merged

qdaxb merged 1 commit into
mainfrom
fix/wework-main-window-close

Conversation

@qdaxb

@qdaxb qdaxb commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • restore handling for every intercepted first main-window close request, including when no runtime task is running
  • route the Windows custom close button through Tauri's standard window close request
  • add unit coverage for the close guard and Windows frame control
  • extend the desktop E2E controller and lifecycle scenario to exercise the native close request, cancellation, and confirmation paths
  • document the new isolated ai:verify request-close command

Why

The Rust window lifecycle handler prevents the first close and emits a close-to-tray hint request. A runtime lifecycle refactor ignored that event when no task was running, leaving the close request prevented with no visible response. Separately, the Windows custom frame button directly destroyed the main WebView instead of following the same close-request path as native window controls.

This change makes native and custom close controls share one lifecycle flow and restores the close-to-tray confirmation behavior.

User impact

  • clicking the main-window close button now shows the first-run background-mode prompt instead of doing nothing
  • cancelling keeps the window open
  • confirming closes the main window while Wework continues running in the tray
  • Windows custom controls now respect the same preferences and confirmation behavior as native controls

Validation

  • pre-push ESLint, TypeScript, and unit test suite
  • focused Vitest coverage: 3 files, 15 tests
  • Prettier and git diff --check
  • isolated real-Tauri verification:
    • close request without a running task displayed the prompt
    • cancellation kept the window open
    • confirmation produced the native windowWillClose event and destroyed the main WebView while keeping the app process running

Summary by CodeRabbit

  • New Features

    • Added a close-request flow that displays a confirmation dialog before closing the desktop window.
    • Added support for closing the window after confirming the dialog, including during background task activity.
  • Bug Fixes

    • Improved close-button behavior by using the standard desktop window close flow.
    • Ensured the close confirmation appears consistently when requesting to close the window.
  • Documentation

    • Documented the new desktop verification command for testing close requests and close-to-tray behavior.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a request-close desktop verification command, routes it through E2E automation, updates runtime close-guard behavior, simplifies the window close button, and expands desktop lifecycle tests for cancelling and confirming close requests.

Changes

Main-window close flow

Layer / File(s) Summary
Runtime close guard behavior
wework/src/features/workbench/RuntimeTaskCloseGuard.tsx, wework/src/features/workbench/RuntimeTaskCloseGuard.test.tsx
The close guard installs on mount and opens the confirmation overlay for intercepted close requests, with focused test coverage.
Close control paths
wework/src/components/layout/WindowFrameControls.*, wework/scripts/ai-verify.mjs, wework/src/e2e/automation.ts
The close button directly closes the current window, while request-close maps to requestMainWindowClose and closes the main window through desktop automation.
Close-flow validation
wework/e2e/desktop/task-flow.e2e.mjs, wework/AGENTS.md
Desktop E2E coverage validates cancelling and confirming close requests, and verification guidance documents the new command.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AIVerify
  participant DesktopAutomation
  participant MainWindow
  participant RuntimeTaskCloseGuard
  participant CloseOverlay
  AIVerify->>DesktopAutomation: request-close
  DesktopAutomation->>MainWindow: requestMainWindowClose
  MainWindow->>RuntimeTaskCloseGuard: close request
  RuntimeTaskCloseGuard->>CloseOverlay: show confirmation
  CloseOverlay-->>MainWindow: cancel or confirm
Loading

Possibly related PRs

Suggested reviewers: sdadunderscoresdad, ficohu, micro66

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: restoring the main window close flow.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wework-main-window-close

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qdaxb
qdaxb marked this pull request as ready for review July 30, 2026 06:51
@qdaxb
qdaxb enabled auto-merge July 30, 2026 06:51

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wework/src/e2e/automation.ts`:
- Around line 728-729: In the closeMainWindowToTray and requestMainWindowClose
handlers, invoke closeMainWindowToTray() or getCurrentWindow().close() before
awaiting postDesktopControlResult with ok: true. Preserve the surrounding
result-handling flow so close/tray failures are reported instead of posting
success first.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 56e21b2f-d2bb-442c-abf2-476b24cf6bc8

📥 Commits

Reviewing files that changed from the base of the PR and between eda8ca3 and ddb6a2e.

📒 Files selected for processing (8)
  • wework/AGENTS.md
  • wework/e2e/desktop/task-flow.e2e.mjs
  • wework/scripts/ai-verify.mjs
  • wework/src/components/layout/WindowFrameControls.test.tsx
  • wework/src/components/layout/WindowFrameControls.tsx
  • wework/src/e2e/automation.ts
  • wework/src/features/workbench/RuntimeTaskCloseGuard.test.tsx
  • wework/src/features/workbench/RuntimeTaskCloseGuard.tsx

Comment on lines +728 to +729
case 'requestMainWindowClose':
return ''

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file =="
fd -a 'automation\.ts$' . || true

echo "== file size =="
wc -l wework/src/e2e/automation.ts

echo "== outline relevant regions =="
sed -n '700,745p' wework/src/e2e/automation.ts | cat -n -v
echo "---"
sed -n '1055,1095p' wework/src/e2e/automation.ts | cat -n -v

echo "== command/action definitions and close handling search =="
rg -n "requestMainWindowClose|closeMainWindowToTray|postDesktopControlResult|executeDesktopControlCommand|getCurrentWindow\\(\\)\\.close|Action" wework/src/e2e/automation.ts

Repository: wecode-ai/Wegent

Length of output: 5402


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== webviewWindow imports and definitions =="
rg -n "getCurrentWindow|WebviewWindow|DesktopControlCommand|DesktopControlResult" wework/src/e2e/automation.ts wework/src/types/automation.ts

echo "== automation type definitions =="
sed -n '1,180p' wework/src/types/automation.ts | cat -n -v

echo "== imports surrounding automation.ts =="
sed -n '1,45p' wework/src/e2e/automation.ts | cat -n -v

echo "== inspect Tauri API docs package if present =="
fd -a '(^window\.json$|window\.mjs$|tsconfig.*\.json$)' . | sed -n '1,80p'
rg -n "`@tauri-apps/api/webviewWindow`|`@tauri-apps/api/window`|WebviewWindow" -S . --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**' | sed -n '1,120p'

Repository: wecode-ai/Wegent

Length of output: 13449


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate desktop-control contract files =="
fd -a 'desktop-control|desktop' . | rg 'desktop-control|desktop' | sed -n '1,120p'

echo "== files containing DesktopControlCommand =="
rg -n "interface DesktopControlCommand|type DesktopControlCommand|export .*DesktopControlCommand|enum .*Desktop.*Action|case 'requestMainWindowClose'|closeMainWindowToTray" . --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build /**' | sed -n '1,200p'

Repository: wecode-ai/Wegent

Length of output: 2824


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== desktop-control-contract =="
cat -n -v wework/src/extensions/desktop-control-contract.ts | sed -n '1,220p'

echo "== automation lines 670-750 =="
cat -n -v wework/src/e2e/automation.ts | sed -n '670,750p'

echo "== automation lines 1068-1092 =="
cat -n -v wework/src/e2e/automation.ts | sed -n '1068,1092p'

Repository: wecode-ai/Wegent

Length of output: 5835


🌐 Web query:

Tauri v2 WebviewWindow getCurrentWindow close returns a promise documentation

💡 Result:

In Tauri v2, the close() method on a WebviewWindow instance returns a Promise<void> [1][2]. When you call getCurrentWebviewWindow().close(), it triggers a close-requested event, which allows the application to intercept the action if necessary [3][2]. Because it returns a promise, you can await the call if you need to ensure the action has been processed by the core process [1][2]. Key technical details: - Module: The getCurrentWebviewWindow function is exported from the @tauri-apps/api/webviewWindow module [4][5]. - Behavior: The close() method does not force the window to close immediately; it initiates a request that the window close [3][2]. If you need to force a window to close immediately, the documentation recommends using the destroy() method instead [3][2]. - Usage: It is commonly used in patterns where a specific window needs to close itself (e.g., a settings or dialog window) [5].

Citations:


Move getCurrentWindow().close() before posting the close result.

For both closeMainWindowToTray and requestMainWindowClose, postDesktopControlResult(..., ok: true) is already awaited before the actual close/tray request, so failures from those calls are reported after the desktop-control client has already resolved successfully. Issue the closeMainWindowToTray() / getCurrentWindow().close() calls before writing the success result, and let the surrounding result-handling flow report any failure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wework/src/e2e/automation.ts` around lines 728 - 729, In the
closeMainWindowToTray and requestMainWindowClose handlers, invoke
closeMainWindowToTray() or getCurrentWindow().close() before awaiting
postDesktopControlResult with ok: true. Preserve the surrounding result-handling
flow so close/tray failures are reported instead of posting success first.

Source: Coding guidelines

@qdaxb
qdaxb added this pull request to the merge queue Jul 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 30, 2026
@qdaxb
qdaxb added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 88a0c2b Jul 30, 2026
57 of 59 checks passed
@qdaxb
qdaxb deleted the fix/wework-main-window-close branch July 30, 2026 09:17
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