Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Fix a crash: the thermal state change arrives off the main thread

Claudef931645ee0f9
diff --git a/NotchBuddy/Sources/App/MachineVitals.swift b/NotchBuddy/Sources/App/MachineVitals.swift
index 928e95e2..7763fc72 100644
--- a/NotchBuddy/Sources/App/MachineVitals.swift
+++ b/NotchBuddy/Sources/App/MachineVitals.swift
@@ -47,13 +47,16 @@ final class MachineVitals: ObservableObject {
/// Starts following whether Mochi is on screen. Called once at launch.
func start() {
let state = AppState.shared
- state.$mode.removeDuplicates().sink { [weak self] _ in
+ // Everything is received on the main thread: macOS posts some of these (the thermal
+ // state) from a background queue, and Mochi's code only runs on the main one.
+ state.$mode.removeDuplicates().receive(on: DispatchQueue.main).sink { [weak self] _ in
Task { @MainActor in self?.refreshRunning() }
}.store(in: &subscriptions)
- state.$mochiOnDesktop.removeDuplicates().sink { [weak self] _ in
+ state.$mochiOnDesktop.removeDuplicates().receive(on: DispatchQueue.main).sink { [weak self] _ in
Task { @MainActor in self?.refreshRunning() }
}.store(in: &subscriptions)
NotificationCenter.default.publisher(for: ProcessInfo.thermalStateDidChangeNotification)
+ .receive(on: DispatchQueue.main)
.sink { [weak self] _ in Task { @MainActor in self?.sample() } }
.store(in: &subscriptions)
refreshRunning()