Coffee mode: ☕ left of the fold button keeps the Mac and display awake

One IOPM PreventUserIdleDisplaySleep assertion (released automatically if BroV quits);
the choice is remembered across BroV restarts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maksarsanjeev
2026-10-10 02:23:17 +03:00
parent 2f1c82dc05
commit 717ef02155
3 changed files with 62 additions and 0 deletions
+1
View File
@@ -27,6 +27,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
setupMenuBarItem()
CodexUsageMonitor.shared.start()
NetCore.shared.startWatchingNetwork()
_ = Coffee.shared // restores coffee mode after a BroV restart
AgentWatch.shared.start()
AgentAuth.shared.start()
setupIsland()
+59
View File
@@ -0,0 +1,59 @@
import SwiftUI
import IOKit.pwr_mgt
// MARK: - Coffee mode (header ☕)
//
// Keeps the Mac and its display awake, like `caffeinate -d`: one IOPM assertion that
// macOS drops by itself if BroV quits. The choice survives BroV restarts.
@MainActor
final class Coffee: ObservableObject {
static let shared = Coffee()
private static let key = "coffeeMode"
@Published private(set) var on = false
private var assertion: IOPMAssertionID = 0
private init() {
if UserDefaults.standard.bool(forKey: Self.key) { set(true) }
}
func toggle() { set(!on) }
private func set(_ value: Bool) {
if value, assertion == 0 {
var id: IOPMAssertionID = 0
let ok = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep as CFString,
IOPMAssertionLevel(kIOPMAssertionLevelOn),
"BroV: кофе-режим" as CFString, &id)
guard ok == kIOReturnSuccess else { return }
assertion = id
} else if !value, assertion != 0 {
IOPMAssertionRelease(assertion)
assertion = 0
}
on = value
UserDefaults.standard.set(value, forKey: Self.key)
}
}
struct CoffeeButton: View {
@ObservedObject private var coffee = Coffee.shared
var body: some View {
Button {
coffee.toggle()
SoundEngine.shared.play(coffee.on ? "pop" : "close")
Haptic.tap()
} label: {
Image(systemName: coffee.on ? "cup.and.saucer.fill" : "cup.and.saucer")
.font(.system(size: 13, weight: .semibold))
.foregroundColor(coffee.on ? Color(hex: "#D97757") : Color(hex: "#8E939C"))
.frame(width: 22, height: 22)
.background(Circle().fill(Color(hex: "#D97757").opacity(coffee.on ? 0.16 : 0)))
}
.buttonStyle(.plain)
.help(coffee.on ? "Кофе-режим включён: Мак и экран не засыпают. Нажми, чтобы выключить"
: "Кофе-режим: не давать Маку и экрану засыпать")
}
}
@@ -604,6 +604,8 @@ struct IslandHeader: View {
// Plan limits live inside the Claude / ChatGPT pills (AppGridView):
// here they ran under the camera.
HStack(spacing: 14) {
CoffeeButton()
// Fold everything back into the notch (and the chat to its normal size).
Button(action: {
state.chatDragHeight = nil