mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-14 12:46:05 +00:00
Replace async NotificationCenter with traditional observer pattern
Swift 6 has issues with NotificationCenter's AsyncSequence returning non-Sendable types. Use traditional selector-based observer to avoid concurrency issues.
This commit is contained in:
parent
cc4ba06266
commit
f52c410fe9
1 changed files with 14 additions and 4 deletions
|
|
@ -64,6 +64,10 @@ class ServerManager {
|
|||
setupLogStream()
|
||||
setupObservers()
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
private func setupLogStream() {
|
||||
logStream = AsyncStream { continuation in
|
||||
|
|
@ -73,11 +77,17 @@ class ServerManager {
|
|||
|
||||
private func setupObservers() {
|
||||
// Watch for server mode changes when the value actually changes
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(userDefaultsDidChange),
|
||||
name: UserDefaults.didChangeNotification,
|
||||
object: nil
|
||||
)
|
||||
}
|
||||
|
||||
@objc private func userDefaultsDidChange() {
|
||||
Task { @MainActor in
|
||||
let notifications = NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification)
|
||||
for await _ in notifications {
|
||||
await handleServerModeChange()
|
||||
}
|
||||
await handleServerModeChange()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue