diff --git a/NotchBuddy/Sources/App/AppDelegate.swift b/NotchBuddy/Sources/App/AppDelegate.swift index af6a30f..1366a3e 100644 --- a/NotchBuddy/Sources/App/AppDelegate.swift +++ b/NotchBuddy/Sources/App/AppDelegate.swift @@ -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() diff --git a/NotchBuddy/Sources/App/Coffee.swift b/NotchBuddy/Sources/App/Coffee.swift new file mode 100644 index 0000000..13d46c1 --- /dev/null +++ b/NotchBuddy/Sources/App/Coffee.swift @@ -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 ? "Кофе-режим включён: Мак и экран не засыпают. Нажми, чтобы выключить" + : "Кофе-режим: не давать Маку и экрану засыпать") + } +} diff --git a/NotchBuddy/Sources/App/IslandRootView.swift b/NotchBuddy/Sources/App/IslandRootView.swift index f362c67..764db18 100644 --- a/NotchBuddy/Sources/App/IslandRootView.swift +++ b/NotchBuddy/Sources/App/IslandRootView.swift @@ -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