mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
BugFix: Multiple object creation
This commit is contained in:
parent
1a45d4e7f4
commit
f4bcb96906
8 changed files with 202 additions and 33 deletions
|
|
@ -7,31 +7,38 @@
|
|||
|
||||
import Foundation
|
||||
import Defaults
|
||||
import Combine
|
||||
|
||||
class SystemHUDManager: ObservableObject {
|
||||
class SystemHUDManager {
|
||||
static let shared = SystemHUDManager()
|
||||
|
||||
private var changesObserver: SystemChangesObserver?
|
||||
private weak var coordinator: DynamicIslandViewCoordinator?
|
||||
|
||||
@Default(.enableSystemHUD) var enableSystemHUD {
|
||||
didSet {
|
||||
Task { @MainActor in
|
||||
if enableSystemHUD {
|
||||
await startSystemHUD()
|
||||
} else {
|
||||
await stopSystemHUD()
|
||||
}
|
||||
}
|
||||
}
|
||||
private init() {
|
||||
// Set up observer for settings changes
|
||||
setupSettingsObserver()
|
||||
}
|
||||
|
||||
private init() {}
|
||||
private func setupSettingsObserver() {
|
||||
// Use Defaults publisher instead of @Default property wrapper
|
||||
Defaults.publisher(.enableSystemHUD, options: []).sink { [weak self] change in
|
||||
Task { @MainActor in
|
||||
if change.newValue {
|
||||
await self?.startSystemHUD()
|
||||
} else {
|
||||
await self?.stopSystemHUD()
|
||||
}
|
||||
}
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
func setup(coordinator: DynamicIslandViewCoordinator) {
|
||||
self.coordinator = coordinator
|
||||
|
||||
if enableSystemHUD {
|
||||
if Defaults[.enableSystemHUD] {
|
||||
Task { @MainActor in
|
||||
await startSystemHUD()
|
||||
}
|
||||
|
|
@ -56,6 +63,7 @@ class SystemHUDManager: ObservableObject {
|
|||
|
||||
@MainActor
|
||||
private func stopSystemHUD() async {
|
||||
changesObserver?.stopObserving()
|
||||
changesObserver = nil
|
||||
|
||||
// Re-enable system HUD
|
||||
|
|
@ -65,18 +73,36 @@ class SystemHUDManager: ObservableObject {
|
|||
}
|
||||
|
||||
private func disableSystemHUD() {
|
||||
print("🔇 Disabling system HUD (OSDUIHelper running: \(SystemOSDManager.isOSDUIHelperRunning()))")
|
||||
// Disable the system HUD using SystemOSDManager
|
||||
SystemOSDManager.disableSystemHUD()
|
||||
}
|
||||
|
||||
private func enableOriginalSystemHUD() {
|
||||
print("🔊 Re-enabling system HUD (OSDUIHelper running: \(SystemOSDManager.isOSDUIHelperRunning()))")
|
||||
// Re-enable the system HUD using SystemOSDManager
|
||||
SystemOSDManager.enableSystemHUD()
|
||||
|
||||
// Verify it's working after a short delay
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
let isRunning = SystemOSDManager.isOSDUIHelperRunning()
|
||||
print("🔍 OSDUIHelper status after re-enable: \(isRunning ? "✅ Running" : "❌ Not running")")
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
print("🧹 SystemHUDManager deinitializing - ensuring system HUD is restored")
|
||||
cancellables.removeAll()
|
||||
Task { @MainActor in
|
||||
await stopSystemHUD()
|
||||
}
|
||||
// Also call the emergency restore as backup
|
||||
SystemHUDDebugger.forceRestartOSDUIHelper()
|
||||
}
|
||||
|
||||
/// Emergency restore function - call this if system HUD is not working
|
||||
public static func emergencyRestoreSystemHUD() {
|
||||
print("🚨 Emergency system HUD restore initiated")
|
||||
SystemHUDDebugger.forceRestartOSDUIHelper()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue