Skip to content

Commit

Permalink
Workaround for Sequoia launch behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Sep 17, 2024
1 parent 2397553 commit c948e31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
9 changes: 3 additions & 6 deletions Ice/Main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
}

// On macOS 15, the windows handle their own closure. If on macOS 14,
// close them here.
//
// NOTE: The windows might not close when running from Xcode, but it
// does work when running standalone.
if #unavailable(macOS 15.0) {
// Temporary hack to make sure the window opens on Sequoia is to
// let them open, wait a bit, then close them.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
appState.settingsWindow?.close()
appState.permissionsWindow?.close()
}
Expand Down
31 changes: 6 additions & 25 deletions Ice/Settings/SettingsWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SwiftUI

struct SettingsWindow: Scene {
@ObservedObject var appState: AppState
@Environment(\.openWindow) private var openWindow

var body: some Scene {
settingsWindow
Expand All @@ -19,18 +20,15 @@ struct SettingsWindow: Scene {

private var settingsWindow: some Scene {
if #available(macOS 15.0, *) {
return SettingsWindowMacOS15()
return window
.defaultLaunchBehavior(.presented)
} else {
return SettingsWindowMacOS14()
return window
}
}
}

@available(macOS 14.0, *)
private struct SettingsWindowMacOS14: Scene {
@Environment(\.openWindow) private var openWindow

var body: some Scene {
@SceneBuilder
private var window: some Scene {
Window(Constants.settingsWindowTitle, id: Constants.settingsWindowID) {
SettingsView()
.once {
Expand All @@ -39,20 +37,3 @@ private struct SettingsWindowMacOS14: Scene {
}
}
}

@available(macOS 15.0, *)
private struct SettingsWindowMacOS15: Scene {
@Environment(\.dismissWindow) private var dismissWindow
@State private var launchBehavior: SceneLaunchBehavior = .presented

var body: some Scene {
Window(Constants.settingsWindowTitle, id: Constants.settingsWindowID) {
SettingsView()
.once {
dismissWindow(id: Constants.settingsWindowID)
launchBehavior = .suppressed // Keep the window from reopening.
}
}
.defaultLaunchBehavior(launchBehavior)
}
}

0 comments on commit c948e31

Please sign in to comment.