Skip to content

fix: prevent duplicate window on reopen from dock#92

Merged
sozercan merged 3 commits intomainfrom
fix/duplicate-window-on-reopen
Feb 4, 2026
Merged

fix: prevent duplicate window on reopen from dock#92
sozercan merged 3 commits intomainfrom
fix/duplicate-window-on-reopen

Conversation

@sozercan
Copy link
Owner

@sozercan sozercan commented Feb 4, 2026

Summary

  • Use Window scene instead of WindowGroup to prevent duplicate windows when reopening from dock

Problem

When closing the window (hiding, not quitting) and clicking the dock icon to reopen, two windows appeared:

  1. The original hidden window shown by applicationShouldHandleReopen
  2. A new window created by SwiftUI's WindowGroup (which creates new instances when no visible window exists)

Solution

Changed from WindowGroup to Window("Kaset", id: "main") which is a single-instance scene type that correctly handles the hidden window case without creating duplicates.

Test plan

  • Launch app
  • Close window (Cmd+W or click red button)
  • Click dock icon to reopen
  • Verify only one window appears

Copilot AI review requested due to automatic review settings February 4, 2026 06:36
Use Window scene instead of WindowGroup to prevent SwiftUI from
creating a second window when the app is reopened via dock icon
while the original window is hidden (not closed).

WindowGroup is designed for multi-window apps and creates a new
window instance when no visible window exists. Window is a single-
instance scene type that correctly handles the hidden window case.
@sozercan sozercan force-pushed the fix/duplicate-window-on-reopen branch from 3d5cd9e to b4ce482 Compare February 4, 2026 06:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where clicking the dock icon to reopen the app after closing the window would create duplicate windows. The fix changes the scene type from WindowGroup to Window with a unique ID.

Changes:

  • Changed from WindowGroup scene to Window("Kaset", id: "main") scene to prevent duplicate window creation
  • The Window scene type is a single-instance scene that correctly handles the hidden window case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sozercan sozercan merged commit 1a192e0 into main Feb 4, 2026
6 checks passed
@sozercan sozercan deleted the fix/duplicate-window-on-reopen branch February 4, 2026 07:06
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.

2 participants