mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
batteria finale, waiting for approve
This commit is contained in:
parent
1d53bbac13
commit
945707425a
9 changed files with 1091 additions and 89 deletions
|
|
@ -21,7 +21,7 @@ import Defaults
|
|||
|
||||
/// A view that displays the battery status with an icon and charging indicator.
|
||||
struct BatteryView: View {
|
||||
|
||||
@Default(.showPowerStatusIcons) var showPowerStatusIcons
|
||||
var levelBattery: Float
|
||||
var isPluggedIn: Bool
|
||||
var isCharging: Bool
|
||||
|
|
@ -79,7 +79,7 @@ struct BatteryView: View {
|
|||
)
|
||||
.padding(.leading, 2)
|
||||
|
||||
if iconStatus != "" && (isForNotification || Defaults[.showPowerStatusIcons]) {
|
||||
if iconStatus != "" && (isForNotification || showPowerStatusIcons) {
|
||||
ZStack {
|
||||
Image(iconStatus)
|
||||
.resizable()
|
||||
|
|
@ -182,6 +182,7 @@ struct BatteryMenuView: View {
|
|||
/// A view that displays the battery status and allows interaction to show detailed information.
|
||||
struct DynamicIslandBatteryView: View {
|
||||
|
||||
@Default(.showBatteryPercentage) var showBatteryPercentage
|
||||
@State var batteryWidth: CGFloat = 26
|
||||
var isCharging: Bool = false
|
||||
var isInLowPowerMode: Bool = false
|
||||
|
|
@ -199,7 +200,7 @@ struct DynamicIslandBatteryView: View {
|
|||
|
||||
var body: some View {
|
||||
HStack {
|
||||
if Defaults[.showBatteryPercentage] {
|
||||
if showBatteryPercentage {
|
||||
ZStack(alignment: .trailing) {
|
||||
Text("100%")
|
||||
.font(.callout)
|
||||
|
|
@ -268,6 +269,443 @@ struct DynamicIslandBatteryView: View {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private struct BatteryTemporaryHUDMetrics {
|
||||
let width: CGFloat
|
||||
let height: CGFloat
|
||||
let topRadius: CGFloat
|
||||
let bottomRadius: CGFloat
|
||||
}
|
||||
|
||||
private extension BatteryTemporaryHUDKind {
|
||||
func metrics(
|
||||
style: BatteryNotificationStyle,
|
||||
closedNotchWidth: CGFloat,
|
||||
baseHeight: CGFloat
|
||||
) -> BatteryTemporaryHUDMetrics {
|
||||
let compactBaseRadius = max(baseHeight / 2, 16)
|
||||
let compactTopRadius = max(12, compactBaseRadius - 4)
|
||||
|
||||
switch (self, style) {
|
||||
case (.charging, _), (.lowBattery, .compact), (.fullBattery, .compact):
|
||||
return BatteryTemporaryHUDMetrics(
|
||||
width: closedNotchWidth + 180,
|
||||
height: baseHeight,
|
||||
topRadius: compactTopRadius,
|
||||
bottomRadius: compactBaseRadius
|
||||
)
|
||||
case (.lowBattery, .standard):
|
||||
return BatteryTemporaryHUDMetrics(
|
||||
width: closedNotchWidth + 150,
|
||||
height: baseHeight + 75,
|
||||
topRadius: 22,
|
||||
bottomRadius: 40
|
||||
)
|
||||
case (.fullBattery, .standard):
|
||||
return BatteryTemporaryHUDMetrics(
|
||||
width: closedNotchWidth + 140,
|
||||
height: baseHeight + 70,
|
||||
topRadius: 18,
|
||||
bottomRadius: 36
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct BatteryCompactStatusRow: View {
|
||||
let title: String
|
||||
let batteryLevel: Int
|
||||
let tint: Color
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(verbatim: title)
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.white.opacity(0.8))
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 6) {
|
||||
Text("\(batteryLevel)%")
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(tint)
|
||||
|
||||
HStack(spacing: 1.5) {
|
||||
ZStack(alignment: .leading) {
|
||||
RoundedRectangle(cornerRadius: 6, style: .continuous)
|
||||
.fill(tint.opacity(0.3))
|
||||
|
||||
GeometryReader { geo in
|
||||
let clamped = max(0, min(batteryLevel, 100))
|
||||
let width = CGFloat(clamped) / 100 * geo.size.width
|
||||
Rectangle()
|
||||
.fill(tint.gradient)
|
||||
.frame(width: max(0, width))
|
||||
}
|
||||
}
|
||||
.frame(width: 28, height: 16)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
|
||||
|
||||
RoundedRectangle(cornerRadius: 1.5, style: .continuous)
|
||||
.fill(batteryLevel == 100 ? tint.gradient : tint.opacity(0.3).gradient)
|
||||
.frame(width: 2, height: 6)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
}
|
||||
|
||||
struct BatteryTemporaryActivityView: View {
|
||||
let kind: BatteryTemporaryHUDKind
|
||||
let batteryLevel: Int
|
||||
let isLowPowerMode: Bool
|
||||
let closedNotchWidth: CGFloat
|
||||
let baseHeight: CGFloat
|
||||
let isDynamicIslandMode: Bool
|
||||
let topCornerRadius: CGFloat
|
||||
@Default(.lowBatteryHUDStyle) var lowBatteryHUDStyle
|
||||
@Default(.fullBatteryHUDStyle) var fullBatteryHUDStyle
|
||||
var styleOverride: BatteryNotificationStyle? = nil
|
||||
|
||||
@State private var pulse = false
|
||||
@State private var showBatteryIndicator = false
|
||||
@State private var changeBatteryIndicator = true
|
||||
|
||||
private var style: BatteryNotificationStyle {
|
||||
if kind == .charging {
|
||||
return .compact
|
||||
}
|
||||
if let styleOverride {
|
||||
return styleOverride
|
||||
}
|
||||
switch kind {
|
||||
case .charging:
|
||||
return .compact
|
||||
case .lowBattery:
|
||||
return lowBatteryHUDStyle
|
||||
case .fullBattery:
|
||||
return fullBatteryHUDStyle
|
||||
}
|
||||
}
|
||||
|
||||
private var metrics: BatteryTemporaryHUDMetrics {
|
||||
kind.metrics(
|
||||
style: style,
|
||||
closedNotchWidth: closedNotchWidth,
|
||||
baseHeight: baseHeight
|
||||
)
|
||||
}
|
||||
|
||||
private var batteryTint: Color {
|
||||
switch kind {
|
||||
case .charging:
|
||||
if isLowPowerMode {
|
||||
return .yellow
|
||||
} else if batteryLevel <= 20 {
|
||||
return .red
|
||||
}
|
||||
return .green
|
||||
case .lowBattery:
|
||||
return isLowPowerMode ? .yellow : .red
|
||||
case .fullBattery:
|
||||
return isLowPowerMode ? .yellow : .green
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var surfaceShape: AnyShape {
|
||||
if isDynamicIslandMode {
|
||||
return AnyShape(DynamicIslandPillShape(cornerRadius: dynamicIslandPillCornerRadiusInsets.opened))
|
||||
} else {
|
||||
return AnyShape(NotchShape(topCornerRadius: topCornerRadius, bottomCornerRadius: metrics.bottomRadius))
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .bottom) {
|
||||
content
|
||||
}
|
||||
.frame(width: metrics.width, height: metrics.height, alignment: .bottom)
|
||||
.clipShape(surfaceShape)
|
||||
.onAppear(perform: prepareAnimations)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var content: some View {
|
||||
if style == .compact {
|
||||
BatteryCompactStatusRow(
|
||||
title: compactTitle,
|
||||
batteryLevel: batteryLevel,
|
||||
tint: batteryTint
|
||||
)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
} else {
|
||||
VStack {
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: kind == .lowBattery ? 2 : 3) {
|
||||
standardTitle
|
||||
standardDescription
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
standardIndicator
|
||||
}
|
||||
.padding(.leading, kind == .lowBattery ? 40 : 35)
|
||||
.padding(.trailing, kind == .lowBattery ? 45 : 40)
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var compactTitle: String {
|
||||
switch kind {
|
||||
case .charging:
|
||||
return "Charging"
|
||||
case .lowBattery:
|
||||
return "Low Battery"
|
||||
case .fullBattery:
|
||||
return "Full Battery"
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var standardTitle: some View {
|
||||
HStack(spacing: 5) {
|
||||
Text(verbatim: kind == .lowBattery ? "Battery Low" : "Full Battery")
|
||||
.font(.system(size: kind == .lowBattery ? 13 : 13, weight: .semibold))
|
||||
.foregroundStyle(.white.opacity(0.82))
|
||||
.lineLimit(1)
|
||||
|
||||
Text("\(batteryLevel)%")
|
||||
.font(.system(size: kind == .lowBattery ? 12 : 13, weight: .semibold))
|
||||
.foregroundStyle(batteryTint)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var standardDescription: some View {
|
||||
switch kind {
|
||||
case .charging:
|
||||
EmptyView()
|
||||
case .lowBattery:
|
||||
if isLowPowerMode {
|
||||
(
|
||||
Text(verbatim: "Low Power Mode enabled")
|
||||
.foregroundColor(.yellow)
|
||||
.font(.system(size: 10, weight: .medium))
|
||||
+
|
||||
Text(verbatim: ", it is recommended to charge it.")
|
||||
.foregroundColor(.gray.opacity(0.6))
|
||||
.font(.system(size: 10, weight: .medium))
|
||||
)
|
||||
} else {
|
||||
Text(verbatim: "Turn on Low Power Mode or it\nis recommended to charge it.")
|
||||
.font(.system(size: 10, weight: .medium))
|
||||
.foregroundStyle(.gray.opacity(0.6))
|
||||
.lineLimit(2)
|
||||
}
|
||||
case .fullBattery:
|
||||
Text(verbatim: "Your Mac is fully charged.")
|
||||
.font(.system(size: 10))
|
||||
.foregroundStyle(.gray.opacity(0.6))
|
||||
.fontWeight(.medium)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var standardIndicator: some View {
|
||||
switch kind {
|
||||
case .charging:
|
||||
EmptyView()
|
||||
case .lowBattery:
|
||||
if isLowPowerMode {
|
||||
yellowLowIndicator
|
||||
} else {
|
||||
redLowIndicator
|
||||
}
|
||||
case .fullBattery:
|
||||
if showBatteryIndicator {
|
||||
if isLowPowerMode {
|
||||
yellowFullIndicator
|
||||
.transition(.opacity.combined(with: .scale))
|
||||
} else {
|
||||
greenFullIndicator
|
||||
.transition(.opacity.combined(with: .scale))
|
||||
}
|
||||
} else {
|
||||
magSafeIndicator
|
||||
.transition(.opacity.combined(with: .scale))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var redLowIndicator: some View {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 30)
|
||||
.fill(.red.opacity(0.2))
|
||||
.frame(width: 70, height: 40)
|
||||
|
||||
HStack(spacing: 2) {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.red.opacity(0.4))
|
||||
.frame(width: 40, height: 24)
|
||||
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.red.opacity(0.4))
|
||||
.frame(width: 3, height: 8)
|
||||
}
|
||||
.padding(.trailing, 5)
|
||||
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
.fill(Color.red.gradient)
|
||||
.frame(width: 8, height: 14)
|
||||
.opacity(pulse ? 1 : 0.3)
|
||||
.offset(x: -15)
|
||||
|
||||
RoundedRectangle(cornerRadius: 30)
|
||||
.stroke(Color.red.opacity(0.9), lineWidth: 1.5)
|
||||
.frame(width: pulse ? 8 : 30, height: pulse ? 14 : 32)
|
||||
.offset(x: -15)
|
||||
.opacity(pulse ? 0.3 : 1)
|
||||
}
|
||||
}
|
||||
|
||||
private var yellowLowIndicator: some View {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 30)
|
||||
.fill(.yellow.opacity(0.2))
|
||||
.frame(width: 70, height: 40)
|
||||
|
||||
HStack(spacing: 2) {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.yellow.opacity(0.4))
|
||||
.frame(width: 40, height: 24)
|
||||
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.yellow.opacity(0.4))
|
||||
.frame(width: 3, height: 8)
|
||||
}
|
||||
.padding(.trailing, 5)
|
||||
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
.fill(.yellow.gradient)
|
||||
.frame(width: 8, height: 14)
|
||||
.offset(x: -15)
|
||||
}
|
||||
}
|
||||
|
||||
private var greenFullIndicator: some View {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 30)
|
||||
.fill(.green.opacity(0.2))
|
||||
.frame(width: 70, height: 40)
|
||||
|
||||
HStack(spacing: 2) {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.green.opacity(0.4))
|
||||
.frame(width: 44, height: 24)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 4)
|
||||
.fill(Color.green.gradient)
|
||||
.frame(width: 34, height: 14)
|
||||
.opacity(pulse ? 1 : 0.4)
|
||||
)
|
||||
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.green.opacity(0.4))
|
||||
.frame(width: 3, height: 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var yellowFullIndicator: some View {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 30)
|
||||
.fill(.yellow.opacity(0.2))
|
||||
.frame(width: 70, height: 40)
|
||||
|
||||
HStack(spacing: 2) {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.yellow.opacity(0.4))
|
||||
.frame(width: 44, height: 24)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 4)
|
||||
.fill(Color.yellow.gradient)
|
||||
.frame(width: 34, height: 14)
|
||||
.opacity(pulse ? 1 : 0.4)
|
||||
)
|
||||
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.yellow.opacity(0.4))
|
||||
.frame(width: 3, height: 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var magSafeIndicator: some View {
|
||||
HStack(spacing: 0) {
|
||||
Rectangle()
|
||||
.fill(.gray.opacity(0.15))
|
||||
.frame(width: 30, height: 5)
|
||||
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 2)
|
||||
.fill(.gray.opacity(0.2).gradient)
|
||||
.frame(width: 30, height: 40)
|
||||
|
||||
Circle()
|
||||
.fill(changeBatteryIndicator ? .orange : .green)
|
||||
.shadow(color: changeBatteryIndicator ? .orange : .green, radius: 5)
|
||||
.frame(width: 5, height: 5)
|
||||
}
|
||||
|
||||
Rectangle()
|
||||
.fill(.white.opacity(0.4))
|
||||
.frame(width: 3, height: 32)
|
||||
}
|
||||
}
|
||||
|
||||
private func prepareAnimations() {
|
||||
pulse = false
|
||||
showBatteryIndicator = kind == .fullBattery && style == .standard
|
||||
changeBatteryIndicator = true
|
||||
|
||||
guard style == .standard else { return }
|
||||
|
||||
switch kind {
|
||||
case .charging:
|
||||
break
|
||||
case .lowBattery:
|
||||
if !isLowPowerMode {
|
||||
withAnimation(.easeInOut(duration: 1).repeatForever(autoreverses: true)) {
|
||||
pulse = true
|
||||
}
|
||||
}
|
||||
case .fullBattery:
|
||||
withAnimation(.easeInOut(duration: 1).repeatForever(autoreverses: true)) {
|
||||
pulse = true
|
||||
}
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||
withAnimation(.spring(duration: 0.4)) {
|
||||
showBatteryIndicator = false
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
||||
withAnimation(.spring(duration: 0.2)) {
|
||||
changeBatteryIndicator = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
DynamicIslandBatteryView(
|
||||
batteryWidth: 30,
|
||||
|
|
|
|||
|
|
@ -36,10 +36,12 @@ struct DynamicIslandHeader: View {
|
|||
@Default(.showClipboardIcon) var showClipboardIcon
|
||||
@Default(.showColorPickerIcon) var showColorPickerIcon
|
||||
@Default(.clipboardDisplayMode) var clipboardDisplayMode
|
||||
@Default(.showBatteryIndicator) var showBatteryIndicator
|
||||
@Default(.enableMinimalisticUI) var enableMinimalisticUI
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
if !Defaults[.enableMinimalisticUI] {
|
||||
if !enableMinimalisticUI {
|
||||
HStack {
|
||||
let shouldShowTabs = coordinator.alwaysShowTabs || vm.notchState == .open || !shelfState.items.isEmpty
|
||||
if shouldShowTabs {
|
||||
|
|
@ -55,7 +57,7 @@ struct DynamicIslandHeader: View {
|
|||
|
||||
}
|
||||
|
||||
if vm.notchState == .open && !Defaults[.enableMinimalisticUI] {
|
||||
if vm.notchState == .open && !enableMinimalisticUI {
|
||||
let spacerWidth = min(vm.closedNotchSize.width, 300)
|
||||
Rectangle()
|
||||
.fill(NSScreen.screens
|
||||
|
|
@ -67,7 +69,7 @@ struct DynamicIslandHeader: View {
|
|||
}
|
||||
|
||||
HStack(spacing: 4) {
|
||||
if vm.notchState == .open && !Defaults[.enableMinimalisticUI] {
|
||||
if vm.notchState == .open && !enableMinimalisticUI {
|
||||
if Defaults[.showMirror] {
|
||||
Button(action: {
|
||||
vm.toggleCameraPreview()
|
||||
|
|
@ -230,7 +232,7 @@ struct DynamicIslandHeader: View {
|
|||
|
||||
|
||||
|
||||
if Defaults[.showBatteryIndicator] {
|
||||
if showBatteryIndicator {
|
||||
DynamicIslandBatteryView(
|
||||
batteryWidth: 30,
|
||||
isCharging: batteryModel.isCharging,
|
||||
|
|
|
|||
|
|
@ -731,6 +731,19 @@ struct SettingsView: View {
|
|||
SettingsSearchEntry(tab: .battery, title: "Show power status notifications", keywords: ["notifications", "power"], highlightID: SettingsTab.battery.highlightID(for: "Show power status notifications")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Show power status icons", keywords: ["power icons", "charging icon"], highlightID: SettingsTab.battery.highlightID(for: "Show power status icons")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Play low battery alert sound", keywords: ["low battery", "alert", "sound"], highlightID: SettingsTab.battery.highlightID(for: "Play low battery alert sound")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Charging HUD", keywords: ["battery", "charging", "temporary activity"], highlightID: SettingsTab.battery.highlightID(for: "Charging HUD")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Low battery HUD", keywords: ["battery", "low", "temporary activity"], highlightID: SettingsTab.battery.highlightID(for: "Low battery HUD")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Fully charged HUD", keywords: ["battery", "full", "temporary activity"], highlightID: SettingsTab.battery.highlightID(for: "Fully charged HUD")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Charging duration", keywords: ["charging", "duration", "seconds"], highlightID: SettingsTab.battery.highlightID(for: "Charging duration")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Low battery duration", keywords: ["low battery", "duration", "seconds"], highlightID: SettingsTab.battery.highlightID(for: "Low battery duration")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Full battery duration", keywords: ["full battery", "duration", "seconds"], highlightID: SettingsTab.battery.highlightID(for: "Full battery duration")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Test charging HUD", keywords: ["battery", "test", "charging", "preview"], highlightID: nil),
|
||||
SettingsSearchEntry(tab: .battery, title: "Test low battery HUD", keywords: ["battery", "test", "low", "preview"], highlightID: nil),
|
||||
SettingsSearchEntry(tab: .battery, title: "Test full battery HUD", keywords: ["battery", "test", "full", "preview"], highlightID: nil),
|
||||
SettingsSearchEntry(tab: .battery, title: "Low battery style", keywords: ["battery", "style", "compact", "standard"], highlightID: SettingsTab.battery.highlightID(for: "Low battery style")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Low battery threshold", keywords: ["battery", "threshold", "percent"], highlightID: SettingsTab.battery.highlightID(for: "Low battery threshold")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Full battery style", keywords: ["battery", "style", "compact", "standard"], highlightID: SettingsTab.battery.highlightID(for: "Full battery style")),
|
||||
SettingsSearchEntry(tab: .battery, title: "Full charge threshold", keywords: ["battery", "threshold", "full"], highlightID: SettingsTab.battery.highlightID(for: "Full charge threshold")),
|
||||
|
||||
// HUDs
|
||||
SettingsSearchEntry(tab: .devices, title: "Show Bluetooth device connections", keywords: ["bluetooth", "hud"], highlightID: SettingsTab.devices.highlightID(for: "Show Bluetooth device connections")),
|
||||
|
|
@ -1305,10 +1318,62 @@ struct GeneralSettings: View {
|
|||
}
|
||||
|
||||
struct Charge: View {
|
||||
@ObservedObject private var batteryStatusViewModel = BatteryStatusViewModel.shared
|
||||
@Default(.showPowerStatusNotifications) private var showPowerStatusNotifications
|
||||
@Default(.showChargingBatteryHUD) private var showChargingBatteryHUD
|
||||
@Default(.showLowBatteryHUD) private var showLowBatteryHUD
|
||||
@Default(.showFullBatteryHUD) private var showFullBatteryHUD
|
||||
@Default(.chargingBatteryHUDDuration) private var chargingBatteryHUDDuration
|
||||
@Default(.lowBatteryHUDDuration) private var lowBatteryHUDDuration
|
||||
@Default(.fullBatteryHUDDuration) private var fullBatteryHUDDuration
|
||||
@Default(.lowBatteryHUDThreshold) private var lowBatteryHUDThreshold
|
||||
@Default(.fullBatteryHUDThreshold) private var fullBatteryHUDThreshold
|
||||
@Default(.lowBatteryHUDStyle) private var lowBatteryHUDStyle
|
||||
@Default(.fullBatteryHUDStyle) private var fullBatteryHUDStyle
|
||||
|
||||
private func highlightID(_ title: String) -> String {
|
||||
SettingsTab.battery.highlightID(for: title)
|
||||
}
|
||||
|
||||
private var chargingDurationBinding: Binding<Double> {
|
||||
Binding(
|
||||
get: { Double(chargingBatteryHUDDuration) },
|
||||
set: { chargingBatteryHUDDuration = Int($0.rounded()) }
|
||||
)
|
||||
}
|
||||
|
||||
private var lowBatteryDurationBinding: Binding<Double> {
|
||||
Binding(
|
||||
get: { Double(lowBatteryHUDDuration) },
|
||||
set: { lowBatteryHUDDuration = Int($0.rounded()) }
|
||||
)
|
||||
}
|
||||
|
||||
private var fullBatteryDurationBinding: Binding<Double> {
|
||||
Binding(
|
||||
get: { Double(fullBatteryHUDDuration) },
|
||||
set: { fullBatteryHUDDuration = Int($0.rounded()) }
|
||||
)
|
||||
}
|
||||
|
||||
private var lowBatteryThresholdBinding: Binding<Double> {
|
||||
Binding(
|
||||
get: { Double(lowBatteryHUDThreshold) },
|
||||
set: { lowBatteryHUDThreshold = Int($0.rounded()) }
|
||||
)
|
||||
}
|
||||
|
||||
private var fullBatteryThresholdBinding: Binding<Double> {
|
||||
Binding(
|
||||
get: { Double(fullBatteryHUDThreshold) },
|
||||
set: { fullBatteryHUDThreshold = Int($0.rounded()) }
|
||||
)
|
||||
}
|
||||
|
||||
private func sectionOpacity(_ isEnabled: Bool) -> Double {
|
||||
isEnabled ? 1 : 0.5
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
if BatteryActivityManager.shared.hasBattery() {
|
||||
|
|
@ -1340,6 +1405,157 @@ struct Charge: View {
|
|||
} header: {
|
||||
Text("Battery Information")
|
||||
}
|
||||
Section {
|
||||
Defaults.Toggle(key: .showChargingBatteryHUD) {
|
||||
Text("Charging HUD")
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Charging HUD"))
|
||||
|
||||
Defaults.Toggle(key: .showLowBatteryHUD) {
|
||||
Text("Low battery HUD")
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Low battery HUD"))
|
||||
|
||||
Defaults.Toggle(key: .showFullBatteryHUD) {
|
||||
Text("Fully charged HUD")
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Fully charged HUD"))
|
||||
} header: {
|
||||
Text("Battery HUDs")
|
||||
} footer: {
|
||||
Text("These temporary HUDs recreate the charging, low-battery, and full-battery notch alerts.")
|
||||
}
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Charging duration")
|
||||
Spacer()
|
||||
Text("\(chargingBatteryHUDDuration)s")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Slider(value: chargingDurationBinding, in: 1...10, step: 1)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Charging duration"))
|
||||
.disabled(!showPowerStatusNotifications || !showChargingBatteryHUD)
|
||||
.opacity(sectionOpacity(showPowerStatusNotifications && showChargingBatteryHUD))
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Low battery duration")
|
||||
Spacer()
|
||||
Text("\(lowBatteryHUDDuration)s")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Slider(value: lowBatteryDurationBinding, in: 1...10, step: 1)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Low battery duration"))
|
||||
.disabled(!showPowerStatusNotifications || !showLowBatteryHUD)
|
||||
.opacity(sectionOpacity(showPowerStatusNotifications && showLowBatteryHUD))
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Full battery duration")
|
||||
Spacer()
|
||||
Text("\(fullBatteryHUDDuration)s")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Slider(value: fullBatteryDurationBinding, in: 1...10, step: 1)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Full battery duration"))
|
||||
.disabled(!showPowerStatusNotifications || !showFullBatteryHUD)
|
||||
.opacity(sectionOpacity(showPowerStatusNotifications && showFullBatteryHUD))
|
||||
} header: {
|
||||
Text("HUD Duration")
|
||||
}
|
||||
Section {
|
||||
Button {
|
||||
batteryStatusViewModel.triggerTestHUD(kind: .charging)
|
||||
} label: {
|
||||
Label("Test charging HUD", systemImage: "bolt.fill")
|
||||
}
|
||||
.disabled(!showPowerStatusNotifications || !showChargingBatteryHUD)
|
||||
|
||||
Button {
|
||||
batteryStatusViewModel.triggerTestHUD(kind: .lowBattery)
|
||||
} label: {
|
||||
Label("Test low battery HUD", systemImage: "battery.25")
|
||||
}
|
||||
.disabled(!showPowerStatusNotifications || !showLowBatteryHUD)
|
||||
|
||||
Button {
|
||||
batteryStatusViewModel.triggerTestHUD(kind: .fullBattery)
|
||||
} label: {
|
||||
Label("Test full battery HUD", systemImage: "battery.100")
|
||||
}
|
||||
.disabled(!showPowerStatusNotifications || !showFullBatteryHUD)
|
||||
} header: {
|
||||
Text("HUD Tests")
|
||||
} footer: {
|
||||
Text("Runs the real notch animation on the current target display. If an external screen is using Dynamic Island mode, the battery HUD is sent there first.")
|
||||
}
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Picker("Low battery style", selection: $lowBatteryHUDStyle) {
|
||||
ForEach(BatteryNotificationStyle.allCases) { style in
|
||||
Text(style.title)
|
||||
.tag(style)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
Text("Compact matches the charging HUD. Standard uses the expanded DynamicNotch-style card.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Low battery style"))
|
||||
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Low battery threshold")
|
||||
Spacer()
|
||||
Text("\(lowBatteryHUDThreshold)%")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Slider(value: lowBatteryThresholdBinding, in: 5...30, step: 1)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Low battery threshold"))
|
||||
} header: {
|
||||
Text("Low Battery")
|
||||
}
|
||||
.disabled(!showPowerStatusNotifications || !showLowBatteryHUD)
|
||||
.opacity(sectionOpacity(showPowerStatusNotifications && showLowBatteryHUD))
|
||||
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Picker("Full battery style", selection: $fullBatteryHUDStyle) {
|
||||
ForEach(BatteryNotificationStyle.allCases) { style in
|
||||
Text(style.title)
|
||||
.tag(style)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
Text("Compact keeps the alert inline. Standard uses the taller full-charge HUD with the charging animation.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Full battery style"))
|
||||
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Full charge threshold")
|
||||
Spacer()
|
||||
Text("\(fullBatteryHUDThreshold)%")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Slider(value: fullBatteryThresholdBinding, in: 80...100, step: 1)
|
||||
}
|
||||
.settingsHighlight(id: highlightID("Full charge threshold"))
|
||||
} header: {
|
||||
Text("Full Battery")
|
||||
}
|
||||
.disabled(!showPowerStatusNotifications || !showFullBatteryHUD)
|
||||
.opacity(sectionOpacity(showPowerStatusNotifications && showFullBatteryHUD))
|
||||
} else {
|
||||
ContentUnavailableView {
|
||||
VStack(spacing: 16) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue