Skip to content

Commit

Permalink
Fix windows not in front warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Desbeers committed Oct 29, 2024
1 parent 84db6d1 commit 55fdc16
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Chord Provider/Models/AppDelegateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ import SwiftUI
}
/// Update the recent files list
AppStateModel.shared.recentFiles = NSDocumentController.shared.recentDocumentURLs
welcomeWindowController?.showWindow(nil)
openWindow(controller: welcomeWindowController)
}
/// Close the ``WelcomeView`` window
func closeWelcomeWindow() {
Expand All @@ -141,7 +141,7 @@ import SwiftUI
window.center()
aboutViewController = NSWindowController(window: window)
}
aboutViewController?.showWindow(nil)
openWindow(controller: aboutViewController)
}
/// Close the ``AboutView`` window
func closeAboutWindow() {
Expand All @@ -164,7 +164,7 @@ import SwiftUI
window.center()
mediaPlayerViewController = NSWindowController(window: window)
}
mediaPlayerViewController?.showWindow(nil)
openWindow(controller: mediaPlayerViewController)
}

/// Close the ``MediaPlayerView`` window
Expand All @@ -186,7 +186,7 @@ import SwiftUI
}
closePopover(sender: self)
welcomeWindowController?.window?.close()
exportFolderViewController?.showWindow(nil)
openWindow(controller: exportFolderViewController)
}

// MARK: Chord Database window
Expand All @@ -205,7 +205,17 @@ import SwiftUI
}
closePopover(sender: self)
welcomeWindowController?.window?.close()
chordsDatabaseViewController?.showWindow(nil)
openWindow(controller: chordsDatabaseViewController)
}

// MARK: Open a Window

/// Open a window and make it key and front
/// - Parameter controller: The `NSWindowController` of the window
@MainActor private func openWindow(controller: NSWindowController?) {
controller?.showWindow(nil)
controller?.window?.makeKey()
controller?.window?.orderFrontRegardless()
}

// MARK: Create a default NSWindow
Expand Down

0 comments on commit 55fdc16

Please sign in to comment.