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])
}
#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

View File

@@ -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() {