Double-click to apply, then restart File Explorer.
@objc private func quit() NSApplication.shared.terminate(nil) add battery icon to taskbar
def update_icon(self): percent, is_charging = self.get_battery_status() if percent is not None: icon_image = self.create_battery_icon(percent, is_charging) if self.icon: self.icon.icon = icon_image # Update every 5 seconds threading.Timer(5, self.update_icon).start() Double-click to apply, then restart File Explorer
private func getBatteryPercentage() -> String guard let snapshot = IOPSCopyPowerSourcesInfo()?.takeRetainedValue(), let sources = IOPSCopyPowerSourcesList(snapshot)?.takeRetainedValue() as? [CFTypeRef], let source = sources.first else return "??%" guard let info = IOPSGetPowerSourceDescription(snapshot, source)?.takeUnretainedValue() as? [String: Any] else return "??%" if let currentCapacity = info[kIOPSCurrentCapacityKey] as? Int, let maxCapacity = info[kIOPSMaxCapacityKey] as? Int let percentage = (currentCapacity * 100) / maxCapacity return "\(percentage)%" return "??%" Double-click to apply
def get_battery_status(self): battery = psutil.sensors_battery() if battery: percent = battery.percent is_charging = battery.power_plugged return percent, is_charging return None, None