plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Request]: Support tracking all battery aspects

Open feduke-nukem opened this issue 1 year ago • 5 comments

Plugin

battery_plus

Use case

At the moment, there is no option to track changes in battery level or any other aspect. However, for many apps, it would be quite reasonable to react to such changes, by displaying a snackbar message or sending analytics data.

iOS provides support for this functionality: Documentation for level notification Documentation for power save mode notification

Publishers.Merge3(
            NotificationCenter.default.publisher(for: UIDevice.batteryLevelDidChangeNotification),
            NotificationCenter.default.publisher(for: UIDevice.batteryStateDidChangeNotification),
            NotificationCenter.default.publisher(for: NSNotification.Name.NSProcessInfoPowerStateDidChange)
        )
        .sink { _ in self.onBatteryInfoChanged() }

Android also supports monitoring battery level changes: Documentation Power save mode changed notification

applicationContext?.registerReceiver(
    this,
    IntentFilter().apply {
        addAction(Intent.ACTION_BATTERY_CHANGED)
        addAction(Intent.ACTION_BATTERY_LOW)
        addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)
    }
)

I’m not entirely sure about other platforms, but I would expect similar functionality to be available.

Proposal

class BatteryInfo {
  final double level;
  final bool isLow;
  final bool isInBatterySaveMode;
  final BatteryState state;
}

battery.onBatteryInfoChanged.listen((BatteryInfo info) {
  // Do something with new info
});

I actually already have an implementation for iOS and Android and would be happy to contribute if this proposal is considered useful.

@mhadaily cc

feduke-nukem avatar Jan 30 '25 06:01 feduke-nukem

Please, open up a PR, this might be a useful feature for some.

Although I'm more interested in the implementation details.

IslamRustamov avatar Feb 05 '25 08:02 IslamRustamov

if you create PR i am willing to support Windows and Web i dont have macOS but i think its similar to iOS

tachibana-shin avatar Apr 18 '25 17:04 tachibana-shin

@feduke-nukem are you planning to work on this issue? If not, I would love to take it up

Aryan-Sood avatar May 05 '25 06:05 Aryan-Sood

@feduke-nukem are you planning to work on this issue? If not, I would love to take it up

This issue is still in triage. I will take action as soon as I receive a response from the maintainers.

feduke-nukem avatar May 05 '25 06:05 feduke-nukem

@mhadaily

feduke-nukem avatar Jun 27 '25 13:06 feduke-nukem