@objc private func quit() NSApplication.shared.terminate(nil)

@objc private func toggleMenu() statusItem?.menu?.popUp(positioning: nil, at: NSEvent.mouseLocation, in: nil)

private func setupStatusItem() statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) if let button = statusItem?.button button.title = getBatteryPercentage() button.action = #selector(toggleMenu) button.target = self setupMenu()

private func startMonitoring() timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) [weak self] _ in DispatchQueue.main.async self?.statusItem?.button?.title = self?.getBatteryPercentage() ?? "??%"

Double-click to apply, then restart File Explorer.

// Run the app let app = NSApplication.shared let delegate = AppDelegate() app.delegate = delegate app.run() # For Python versions pip install psutil pillow pystray For Linux GTK version sudo apt-get install python3-gi gir1.2-appindicator3-0.1 For macOS, Swift is built-in Quick Windows Registry Fix Save as enable_battery.reg :

def quit(self, source): Gtk.main_quit() if == " main ": indicator = BatteryIndicator() Gtk.main() macOS (Swift) import Cocoa import IOKit.ps class BatteryStatusItem: NSObject private var statusItem: NSStatusItem? private var timer: Timer?

© Aditya Singh. Some rights reserved.

Buy Me A Coffee