Skip to content

feat: tauri window management#106

Merged
goosewobbler merged 37 commits intomainfrom
feat/tauri-window-management
Feb 3, 2026
Merged

feat: tauri window management#106
goosewobbler merged 37 commits intomainfrom
feat/tauri-window-management

Conversation

@goosewobbler
Copy link
Contributor

@goosewobbler goosewobbler commented Jan 26, 2026

Porting the electron service window management to tauri

@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch 16 times, most recently from edc5ff8 to 0d051dd Compare January 28, 2026 15:14
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

This PR successfully ports Electron service's window management functionality to Tauri, implementing automatic focus detection and window switching capabilities.

Key Changes:

  • Added packages/tauri-service/src/window.ts with window focus management logic that mirrors Electron's approach
  • Implemented three new Rust commands in the Tauri plugin: get_active_window_label, list_windows, and get_window_states
  • Integrated ensureActiveWindowFocus into the service's beforeCommand hook for automatic window focus management
  • Added comprehensive unit tests and E2E tests for window management functionality
  • Improved window switching logic to use exact title matching and build title-to-handle mappings efficiently

Implementation Quality:
The implementation addresses several concerns raised in previous review threads:

  • Uses exact title matching (=== after trim) to prevent false positives
  • Implements efficient window iteration by checking each window only once
  • Sorts window labels lexicographically for consistent ordering despite HashMap's unordered nature
  • Handles missing main window gracefully with proper error propagation
  • Includes well-designed fallback logic for finding active windows across different platforms (Windows webview2 vs Linux WebKit)

The code is well-tested with both unit tests and E2E tests, and the window management logic is generic and framework-agnostic like the Electron service it was ported from.

Confidence Score: 4.5/5

  • This PR is safe to merge with very low risk
  • The implementation is well-tested, addresses previous review concerns, and follows established patterns from the Electron service. The code includes comprehensive error handling and platform-specific logic. Minor deduction only because this is a substantial new feature that would benefit from real-world usage validation.
  • No files require special attention - all implementations are solid

Important Files Changed

Filename Overview
packages/tauri-service/src/window.ts New file implementing window management functionality ported from Electron service, includes focus detection and window switching logic
packages/tauri-plugin/src/commands.rs Added three window management commands: get_active_window_label, list_windows, and get_window_states
packages/tauri-service/test/window.spec.ts Unit tests for window management functions, all tests are correctly implemented and passing
fixtures/e2e-apps/tauri/src-tauri/src/main.rs Added switch_to_main command and splash window creation logic for testing window management
packages/tauri-service/src/service.ts Integrated ensureActiveWindowFocus into beforeCommand hook to automatically manage window focus

Sequence Diagram

sequenceDiagram
    participant Test as Test Code
    participant Service as TauriWorkerService
    participant Window as window.ts
    participant Browser as WebDriver Browser
    participant Plugin as Tauri Plugin (Rust)
    participant App as Tauri App

    Test->>Browser: Execute DOM command (e.g., getTitle)
    Browser->>Service: beforeCommand hook triggered
    Service->>Window: ensureActiveWindowFocus(browser, commandName)
    
    alt Command requires focus check
        Window->>Browser: tauri.execute('get_window_states')
        Browser->>Plugin: invoke('plugin:wdio|get_window_states')
        Plugin->>App: Iterate webview_windows()
        App-->>Plugin: Window details (label, title, is_visible, is_focused)
        Plugin-->>Browser: WindowState[]
        Browser-->>Window: states array
        
        Window->>Window: findActiveWindow(states)
        Note over Window: Priority: visible+focused > visible > focused > first
        
        Window->>Browser: getTitle() - current window
        Browser-->>Window: current title
        
        alt Current title != active window title
            Window->>Browser: getWindowHandles()
            Browser-->>Window: handles array
            
            loop For each handle
                Window->>Browser: switchToWindow(handle)
                Window->>Browser: getTitle()
                Browser-->>Window: window title
                Note over Window: Build titleToHandle map
            end
            
            Window->>Browser: switchToWindow(activeWindow.handle)
            Note over Window: Switch to active window by exact title match
        end
    end
    
    Window-->>Service: Focus ensured
    Service-->>Browser: Continue with command execution
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch 2 times, most recently from cbf2235 to 5fc17ad Compare February 1, 2026 22:52
@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch from 5fc17ad to f09c955 Compare February 1, 2026 22:53
@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch from 3bbe968 to 6415f91 Compare February 2, 2026 15:36
@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch from c872a4e to 59f15ab Compare February 2, 2026 17:32
@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch from 099df2b to 8190c06 Compare February 2, 2026 23:11
@goosewobbler goosewobbler force-pushed the feat/tauri-window-management branch from 8190c06 to a044a9f Compare February 3, 2026 01:29
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 10 comments

Edit Code Review Agent Settings | Greptile

goosewobbler and others added 8 commits February 3, 2026 02:23
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@goosewobbler goosewobbler merged commit b83cdf2 into main Feb 3, 2026
72 checks passed
@goosewobbler goosewobbler deleted the feat/tauri-window-management branch February 3, 2026 11:47
@goosewobbler goosewobbler linked an issue Feb 3, 2026 that may be closed by this pull request
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.

Tauri Service - Window Management

1 participant