spb/poche Public
Agent personnel 100 % on-device — SwiftUI + Apple Foundation Models + EventKit + SwiftData. Aucune API, aucun serveur.
Swift 100%
1//2// ThermalMonitor.swift3// Poche4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//89import Foundation10import Observation1112/// Watches thermal state so we slow down before the system throttles us13/// (CLAUDE.md §9). Battery and heat are the scarcest budgets of a local14/// chat app.15@MainActor16@Observable17final class ThermalMonitor {18 private(set) var state: ProcessInfo.ThermalState = ProcessInfo.processInfo.thermalState19 // App-lifetime object (owned by AgentSession): the observation is never20 // removed, so no deinit — Swift 6 deinits cannot touch isolated state.21 private var observer: (any NSObjectProtocol)?2223 var shouldPauseInference: Bool {24 state == .critical25 }2627 init() {28 observer = NotificationCenter.default.addObserver(29 forName: ProcessInfo.thermalStateDidChangeNotification,30 object: nil,31 queue: .main32 ) { [weak self] _ in33 // Delivered on the main queue; re-read from ProcessInfo because34 // the Notification object is not Sendable and carries nothing.35 MainActor.assumeIsolated {36 self?.state = ProcessInfo.processInfo.thermalState37 }38 }39 }40}41