Minor tweaks

This commit is contained in:
Sindre Sorhus 2024-05-15 00:59:24 +07:00
parent d8a954e69f
commit 3b770e22df
1 changed files with 17 additions and 3 deletions

View File

@ -32,7 +32,7 @@ extension Defaults {
task?.cancel() task?.cancel()
} }
func observe() { private func observe() {
// We only use this on the latest OSes (as of adding this) since the backdeploy library has a lot of bugs. // We only use this on the latest OSes (as of adding this) since the backdeploy library has a lot of bugs.
if #available(macOS 13, iOS 16, tvOS 16, watchOS 9, visionOS 1.0, *) { if #available(macOS 13, iOS 16, tvOS 16, watchOS 9, visionOS 1.0, *) {
task?.cancel() task?.cancel()
@ -44,7 +44,7 @@ extension Defaults {
return return
} }
self.objectWillChange.send() objectWillChange.send()
} }
} }
} else { } else {
@ -221,12 +221,26 @@ extension Defaults {
} }
extension Defaults.Toggle<Text> { extension Defaults.Toggle<Text> {
public init(_ title: some StringProtocol, key: Defaults.Key<Bool>) { public init(
_ title: some StringProtocol,
key: Defaults.Key<Bool>
) {
self.label = { Text(title) } self.label = { Text(title) }
self.observable = .init(key) self.observable = .init(key)
} }
} }
extension Defaults.Toggle<Label<Text, Image>> {
public init(
_ title: some StringProtocol,
systemImage: String,
key: Defaults.Key<Bool>
) {
self.label = { Label(title, systemImage: systemImage) }
self.observable = .init(key)
}
}
extension Defaults.Toggle { extension Defaults.Toggle {
/** /**
Do something when the value changes to a different value. Do something when the value changes to a different value.