mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +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()
|
setupLogStream()
|
||||||
setupObservers()
|
setupObservers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
}
|
||||||
|
|
||||||
private func setupLogStream() {
|
private func setupLogStream() {
|
||||||
logStream = AsyncStream { continuation in
|
logStream = AsyncStream { continuation in
|
||||||
|
|
@ -73,11 +77,17 @@ class ServerManager {
|
||||||
|
|
||||||
private func setupObservers() {
|
private func setupObservers() {
|
||||||
// Watch for server mode changes when the value actually changes
|
// 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
|
Task { @MainActor in
|
||||||
let notifications = NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification)
|
await handleServerModeChange()
|
||||||
for await _ in notifications {
|
|
||||||
await handleServerModeChange()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue