Open Settings in a dedicated resizable macOS window

This commit is contained in:
Arkadiusz Fal
2026-04-22 21:59:34 +02:00
parent 4d45f6870e
commit 397fc46629
2 changed files with 35 additions and 9 deletions

View File

@@ -17,14 +17,20 @@ struct FileCommands: Commands {
} }
.keyboardShortcut("o", modifiers: [.command]) .keyboardShortcut("o", modifiers: [.command])
} }
#if os(macOS) }
CommandGroup(replacing: .appSettings) { }
Button(String(localized: "menu.app.settings")) { #endif
NotificationCenter.default.post(name: .showSettings, object: nil)
} #if os(macOS)
.keyboardShortcut(",", modifiers: [.command]) /// App menu Settings item that opens the dedicated Settings window.
} struct SettingsWindowMenuItem: View {
#endif @Environment(\.openWindow) private var openWindow
var body: some View {
Button(String(localized: "menu.app.settings")) {
openWindow(id: "settings")
}
.keyboardShortcut(",", modifiers: [.command])
} }
} }
#endif #endif

View File

@@ -46,7 +46,9 @@ struct YatteeApp: App {
// First-launch state // First-launch state
@State private var showingICloudAlert = false @State private var showingICloudAlert = false
@State private var showingICloudProgress = false @State private var showingICloudProgress = false
#if os(iOS)
@State private var showingSettings = false @State private var showingSettings = false
#endif
@State private var showingOpenLinkSheet = false @State private var showingOpenLinkSheet = false
init() { init() {
@@ -164,19 +166,23 @@ struct YatteeApp: App {
.appEnvironment(appEnvironment) .appEnvironment(appEnvironment)
} }
#endif #endif
#if !os(tvOS) #if os(iOS)
.sheet(isPresented: $showingSettings) { .sheet(isPresented: $showingSettings) {
SettingsView() SettingsView()
.appEnvironment(appEnvironment) .appEnvironment(appEnvironment)
} }
#endif
#if !os(tvOS)
.sheet(isPresented: $showingOpenLinkSheet) { .sheet(isPresented: $showingOpenLinkSheet) {
OpenLinkSheet() OpenLinkSheet()
.appEnvironment(appEnvironment) .appEnvironment(appEnvironment)
} }
#endif #endif
#if os(iOS)
.onReceive(NotificationCenter.default.publisher(for: .showSettings)) { _ in .onReceive(NotificationCenter.default.publisher(for: .showSettings)) { _ in
showingSettings = true showingSettings = true
} }
#endif
.onReceive(NotificationCenter.default.publisher(for: .showOpenLinkSheet)) { _ in .onReceive(NotificationCenter.default.publisher(for: .showOpenLinkSheet)) { _ in
appEnvironment.navigationCoordinator.isPlayerExpanded = false appEnvironment.navigationCoordinator.isPlayerExpanded = false
showingOpenLinkSheet = true showingOpenLinkSheet = true
@@ -292,6 +298,20 @@ struct YatteeApp: App {
} }
} }
#endif #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() { private func registerBackgroundTasksIfNeeded() {