// LoopFollow // SnoozerViewController.swift import Combine import SwiftUI import UIKit class SnoozerViewController: UIViewController { private var hostingController: UIHostingController? private var cancellables = Set() @State private var snoozeMinutes = 15 override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .black let snoozerView = SnoozerView() let hosting = UIHostingController(rootView: snoozerView) hostingController = hosting // Apply initial appearance hosting.overrideUserInterfaceStyle = Storage.shared.appearanceMode.value.userInterfaceStyle // Listen for appearance setting changes Storage.shared.appearanceMode.$value .receive(on: DispatchQueue.main) .sink { [weak self] mode in self?.hostingController?.overrideUserInterfaceStyle = mode.userInterfaceStyle } .store(in: &cancellables) // Listen for system appearance changes (when in System mode) NotificationCenter.default.publisher(for: .appearanceDidChange) .receive(on: DispatchQueue.main) .sink { [weak self] _ in self?.hostingController?.overrideUserInterfaceStyle = Storage.shared.appearanceMode.value.userInterfaceStyle } .store(in: &cancellables) addChild(hosting) view.addSubview(hosting.view) hosting.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ hosting.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), hosting.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), hosting.view.topAnchor.constraint(equalTo: view.topAnchor), hosting.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) hosting.didMove(toParent: self) } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) if Storage.shared.appearanceMode.value == .system, previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle { hostingController?.overrideUserInterfaceStyle = Storage.shared.appearanceMode.value.userInterfaceStyle } } }