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:
@@ -27,6 +27,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
setupMenuBarItem()
|
setupMenuBarItem()
|
||||||
CodexUsageMonitor.shared.start()
|
CodexUsageMonitor.shared.start()
|
||||||
NetCore.shared.startWatchingNetwork()
|
NetCore.shared.startWatchingNetwork()
|
||||||
|
_ = Coffee.shared // restores coffee mode after a BroV restart
|
||||||
AgentWatch.shared.start()
|
AgentWatch.shared.start()
|
||||||
AgentAuth.shared.start()
|
AgentAuth.shared.start()
|
||||||
setupIsland()
|
setupIsland()
|
||||||
|
|||||||
@@ -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):
|
// Plan limits live inside the Claude / ChatGPT pills (AppGridView):
|
||||||
// here they ran under the camera.
|
// here they ran under the camera.
|
||||||
HStack(spacing: 14) {
|
HStack(spacing: 14) {
|
||||||
|
CoffeeButton()
|
||||||
|
|
||||||
// Fold everything back into the notch (and the chat to its normal size).
|
// Fold everything back into the notch (and the chat to its normal size).
|
||||||
Button(action: {
|
Button(action: {
|
||||||
state.chatDragHeight = nil
|
state.chatDragHeight = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user