diff --git a/DynamicIsland/Assets.xcassets/battery.100percent.slash.symbolset/Contents.json b/DynamicIsland/Assets.xcassets/battery.100percent.slash.symbolset/Contents.json new file mode 100644 index 0000000..67a74cd --- /dev/null +++ b/DynamicIsland/Assets.xcassets/battery.100percent.slash.symbolset/Contents.json @@ -0,0 +1,12 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + }, + "symbols" : [ + { + "filename" : "battery.100percent.slash.svg", + "idiom" : "universal" + } + ] +} diff --git a/DynamicIsland/Assets.xcassets/battery.100percent.slash.symbolset/battery.100percent.slash.svg b/DynamicIsland/Assets.xcassets/battery.100percent.slash.symbolset/battery.100percent.slash.svg new file mode 100644 index 0000000..f777610 --- /dev/null +++ b/DynamicIsland/Assets.xcassets/battery.100percent.slash.symbolset/battery.100percent.slash.svg @@ -0,0 +1,121 @@ + + + + + + + + + + Weight/Scale Variations + Ultralight + Thin + Light + Regular + Medium + Semibold + Bold + Heavy + Black + + + + + + + + + + + Design Variations + Symbols are supported in up to nine weights and three scales. + For optimal layout with text and other symbols, vertically align + symbols with the adjacent text. + + + + + + Margins + Leading and trailing margins on the left and right side of each symbol + can be adjusted by modifying the x-location of the margin guidelines. + Modifications are automatically applied proportionally to all + scales and weights. + + + + Exporting + Symbols should be outlined when exporting to ensure the + design is preserved when submitting to Xcode. + Template v.7.0 + Requires Xcode 17 or greater + Generated from + Typeset at 100.0 points + Small + Medium + Large + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DynamicIsland/Localizable.xcstrings b/DynamicIsland/Localizable.xcstrings index 25c57b3..ed3162a 100644 --- a/DynamicIsland/Localizable.xcstrings +++ b/DynamicIsland/Localizable.xcstrings @@ -3870,6 +3870,9 @@ } } } + }, + "Battery settings and informations are only available on MacBooks" : { + }, "Battery Status" : { "localizations" : { diff --git a/DynamicIsland/components/Settings/SettingsView.swift b/DynamicIsland/components/Settings/SettingsView.swift index d0b9737..7f9fb9a 100644 --- a/DynamicIsland/components/Settings/SettingsView.swift +++ b/DynamicIsland/components/Settings/SettingsView.swift @@ -1064,23 +1064,34 @@ struct Charge: View { var body: some View { Form { - Section { - Defaults.Toggle("Show battery indicator", key: .showBatteryIndicator) - .settingsHighlight(id: highlightID("Show battery indicator")) - Defaults.Toggle("Show power status notifications", key: .showPowerStatusNotifications) - .settingsHighlight(id: highlightID("Show power status notifications")) - Defaults.Toggle("Play low battery alert sound", key: .playLowBatteryAlertSound) - .settingsHighlight(id: highlightID("Play low battery alert sound")) - } header: { - Text("General") - } - Section { - Defaults.Toggle("Show battery percentage", key: .showBatteryPercentage) - .settingsHighlight(id: highlightID("Show battery percentage")) - Defaults.Toggle("Show power status icons", key: .showPowerStatusIcons) - .settingsHighlight(id: highlightID("Show power status icons")) - } header: { - Text("Battery Information") + if BatteryActivityManager.shared.hasBattery() { + Section { + Defaults.Toggle("Show battery indicator", key: .showBatteryIndicator) + .settingsHighlight(id: highlightID("Show battery indicator")) + Defaults.Toggle("Show power status notifications", key: .showPowerStatusNotifications) + .settingsHighlight(id: highlightID("Show power status notifications")) + Defaults.Toggle("Play low battery alert sound", key: .playLowBatteryAlertSound) + .settingsHighlight(id: highlightID("Play low battery alert sound")) + } header: { + Text("General") + } + Section { + Defaults.Toggle("Show battery percentage", key: .showBatteryPercentage) + .settingsHighlight(id: highlightID("Show battery percentage")) + Defaults.Toggle("Show power status icons", key: .showPowerStatusIcons) + .settingsHighlight(id: highlightID("Show power status icons")) + } header: { + Text("Battery Information") + } + } else { + ContentUnavailableView { + VStack(spacing: 16) { + Image("battery.100percent.slash") + .font(.title) + Text("Battery settings and informations are only available on MacBooks") + .font(.title3) + } + } } } .navigationTitle("Battery") diff --git a/DynamicIsland/managers/BatteryActivityManager.swift b/DynamicIsland/managers/BatteryActivityManager.swift index 61b1c66..17bc024 100644 --- a/DynamicIsland/managers/BatteryActivityManager.swift +++ b/DynamicIsland/managers/BatteryActivityManager.swift @@ -304,6 +304,14 @@ class BatteryActivityManager { } } + /// Determines if the device has a battery + /// - Returns: True if the computer has a battery, false otherwhise + func hasBattery() -> Bool { + guard let snapshot = IOPSCopyPowerSourcesInfo()?.takeRetainedValue() else { return false } + guard let sources = IOPSCopyPowerSourcesList(snapshot)?.takeRetainedValue() as? [CFTypeRef] else { return false } + return !sources.isEmpty + } + deinit { stopMonitoring() NotificationCenter.default.removeObserver(self) diff --git a/DynamicIsland/models/Constants.swift b/DynamicIsland/models/Constants.swift index 4d6dc3d..41cd135 100644 --- a/DynamicIsland/models/Constants.swift +++ b/DynamicIsland/models/Constants.swift @@ -483,7 +483,7 @@ extension Defaults.Keys { // MARK: Battery static let showPowerStatusNotifications = Key("showPowerStatusNotifications", default: true) - static let showBatteryIndicator = Key("showBatteryIndicator", default: true) + static let showBatteryIndicator = Key("showBatteryIndicator", default: BatteryActivityManager.shared.hasBattery()) static let showBatteryPercentage = Key("showBatteryPercentage", default: true) static let showPowerStatusIcons = Key("showPowerStatusIcons", default: true) static let playLowBatteryAlertSound = Key("playLowBatteryAlertSound", default: true)