diff --git a/Yattee/Core/FileCommands.swift b/Yattee/Core/FileCommands.swift index ab5cf757..25f35d49 100644 --- a/Yattee/Core/FileCommands.swift +++ b/Yattee/Core/FileCommands.swift @@ -17,14 +17,20 @@ struct FileCommands: Commands { } .keyboardShortcut("o", modifiers: [.command]) } - #if os(macOS) - CommandGroup(replacing: .appSettings) { - Button(String(localized: "menu.app.settings")) { - NotificationCenter.default.post(name: .showSettings, object: nil) - } - .keyboardShortcut(",", modifiers: [.command]) - } - #endif + } +} +#endif + +#if os(macOS) +/// App menu Settings… item that opens the dedicated Settings window. +struct SettingsWindowMenuItem: View { + @Environment(\.openWindow) private var openWindow + + var body: some View { + Button(String(localized: "menu.app.settings")) { + openWindow(id: "settings") + } + .keyboardShortcut(",", modifiers: [.command]) } } #endif diff --git a/Yattee/YatteeApp.swift b/Yattee/YatteeApp.swift index aa596070..eb5bb373 100644 --- a/Yattee/YatteeApp.swift +++ b/Yattee/YatteeApp.swift @@ -46,7 +46,9 @@ struct YatteeApp: App { // First-launch state @State private var showingICloudAlert = false @State private var showingICloudProgress = false + #if os(iOS) @State private var showingSettings = false + #endif @State private var showingOpenLinkSheet = false init() { @@ -164,19 +166,23 @@ struct YatteeApp: App { .appEnvironment(appEnvironment) } #endif - #if !os(tvOS) + #if os(iOS) .sheet(isPresented: $showingSettings) { SettingsView() .appEnvironment(appEnvironment) } + #endif + #if !os(tvOS) .sheet(isPresented: $showingOpenLinkSheet) { OpenLinkSheet() .appEnvironment(appEnvironment) } #endif + #if os(iOS) .onReceive(NotificationCenter.default.publisher(for: .showSettings)) { _ in showingSettings = true } + #endif .onReceive(NotificationCenter.default.publisher(for: .showOpenLinkSheet)) { _ in appEnvironment.navigationCoordinator.isPlayerExpanded = false showingOpenLinkSheet = true @@ -292,6 +298,20 @@ struct YatteeApp: App { } } #endif + #if os(macOS) + Window(String(localized: "menu.app.settings"), id: "settings") { + SettingsView(showCloseButton: false) + .appEnvironment(appEnvironment) + .frame(minWidth: 600, idealWidth: 900, maxWidth: .infinity, minHeight: 400, idealHeight: 600, maxHeight: .infinity) + } + .windowResizability(.contentMinSize) + .defaultSize(width: 900, height: 600) + .commands { + CommandGroup(replacing: .appSettings) { + SettingsWindowMenuItem() + } + } + #endif } private func registerBackgroundTasksIfNeeded() {