Repository navigation
fix(wework): restore main window close flow - #2326
Conversation
📝 WalkthroughWalkthroughThe PR adds a ChangesMain-window close flow
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
wework/AGENTS.mdwework/e2e/desktop/task-flow.e2e.mjswework/scripts/ai-verify.mjswework/src/components/layout/WindowFrameControls.test.tsxwework/src/components/layout/WindowFrameControls.tsxwework/src/e2e/automation.tswework/src/features/workbench/RuntimeTaskCloseGuard.test.tsxwework/src/features/workbench/RuntimeTaskCloseGuard.tsx
| case 'requestMainWindowClose': | ||
| return '' |
There was a problem hiding this comment.
🎯 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.tsRepository: 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:
- 1: https://v2.tauri.app/reference/javascript/api/namespacewebviewwindow/
- 2: https://v2.tauri.app/reference/javascript/api/namespacewindow/
- 3: https://v2.tauri.app/blog/tauri-20/
- 4: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/webviewWindow.ts
- 5: https://www.codegiz.com/blog/tauri-patterns-episode-4-open-a-second-window-in-tauri-2/
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
What changed
ai:verify request-closecommandWhy
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
Validation
git diff --checkwindowWillCloseevent and destroyed the main WebView while keeping the app process runningSummary by CodeRabbit
New Features
Bug Fixes
Documentation