yattee/Shared/Views/OpenSettingsButton.swift

38 lines
957 B
Swift
Raw Permalink Normal View History

2021-10-17 23:06:00 +00:00
import SwiftUI
struct OpenSettingsButton: View {
2021-11-28 14:37:55 +00:00
@Environment(\.presentationMode) private var presentationMode
2021-11-10 22:05:59 +00:00
#if !os(macOS)
private var navigation: NavigationModel { .shared }
2021-11-10 22:05:59 +00:00
#endif
2021-10-17 23:06:00 +00:00
var body: some View {
let button = Button {
2021-11-28 14:37:55 +00:00
presentationMode.wrappedValue.dismiss()
2021-10-17 23:06:00 +00:00
#if os(macOS)
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
#else
navigation.presentingSettings = true
#endif
} label: {
Label("Open Settings", systemImage: "gearshape.2")
}
.buttonStyle(.plain)
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
button
.buttonStyle(.borderedProminent)
} else {
button
}
2021-10-17 23:06:00 +00:00
}
}
struct OpenSettingsButton_Previews: PreviewProvider {
static var previews: some View {
OpenSettingsButton()
}
}