Render Add Source buttons inline on macOS where toolbar items aren't shown

Pre-macOS 26 doesn't reliably surface a detail-pane NavigationStack's
toolbar confirmation items in the window title bar, leaving the
"Add Source" actions invisible. Gate the toolbar placement behind
macOS 26+ and fall back to an inline form/header button on older
macOS across the add-source views and the sources list.
This commit is contained in:
Arkadiusz Fal
2026-05-15 07:55:30 +02:00
parent bc81b03821
commit 37d11b50a8
5 changed files with 172 additions and 40 deletions

View File

@@ -31,6 +31,21 @@ struct AddLocalFolderView: View {
!name.isEmpty && selectedFolderURL != nil
}
/// macOS surfaces toolbar confirmation items from a pushed-in-sheet view
/// reliably only from macOS 26 onward. On older macOS we render the
/// "Add Source" action button inline in the form instead.
private var usesToolbarActionButton: Bool {
#if os(macOS)
if #available(macOS 26, *) {
return true
} else {
return false
}
#else
return false
#endif
}
// MARK: - Body
var body: some View {
@@ -99,16 +114,22 @@ struct AddLocalFolderView: View {
if let result = testResult {
SourceTestResultSection(result: result)
}
if !usesToolbarActionButton {
actionSection
}
}
.formStyle(.grouped)
.navigationTitle(String(localized: "sources.addLocalFolder"))
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button(String(localized: "sources.addSource")) {
addSource()
if usesToolbarActionButton {
ToolbarItem(placement: .confirmationAction) {
Button(String(localized: "sources.addSource")) {
addSource()
}
.disabled(!canAdd)
.keyboardShortcut(.defaultAction)
}
.disabled(!canAdd)
.keyboardShortcut(.defaultAction)
}
}
}