-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// PreferenceObserver.swift | ||
// Air Drop Assistant | ||
// | ||
// Created by Bob Gendler on 11/27/24. | ||
// | ||
import Combine | ||
import Foundation | ||
|
||
|
||
|
||
extension UserDefaults { | ||
@objc dynamic var hideMenuIcon: String? { | ||
return string(forKey: "hideMenuIcon") | ||
} | ||
|
||
@objc dynamic var icon_mode: String? { | ||
return string(forKey: "icon_mode") | ||
} | ||
} | ||
|
||
protocol AppPrefObserverDelegate { | ||
func newPreferenceValue() | ||
} | ||
|
||
class AppPreferencesObserver { | ||
|
||
var delegate: AppPrefObserverDelegate? | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
init() { | ||
let hideMenuIconPref = UserDefaults.standard.publisher(for: \.hideMenuIcon) | ||
let icon_modePref = UserDefaults.standard.publisher(for: \.icon_mode) | ||
|
||
// Combine the two publishers | ||
Publishers.CombineLatest(hideMenuIconPref, icon_modePref) | ||
.sink { _, _ in | ||
self.delegate?.newPreferenceValue() | ||
} | ||
.store(in: &cancellables) | ||
} | ||
} | ||
|
||
// Usage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters