Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/battery_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.9.0

- Add Linux support (`battery_plus_linux`)
- Add macOS support (`battery_plus_macos`)
- Add Windows support (`battery_plus_windows`)
- Rename method channel to avoid conflicts

## 0.8.0

- Transfer to plus-plugins monorepo
Expand Down
2 changes: 1 addition & 1 deletion packages/battery_plus/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group 'io.flutter.plugins.battery'
group 'dev.fluttercommunity.plus.battery'
version '1.0-SNAPSHOT'

buildscript {
Expand Down
2 changes: 1 addition & 1 deletion packages/battery_plus/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.battery">
package="dev.fluttercommunity.plus.battery">
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.battery;
package dev.fluttercommunity.plus.battery;

import android.content.BroadcastReceiver;
import android.content.Context;
Expand All @@ -23,8 +23,8 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;

/** BatteryPlugin */
public class BatteryPlugin implements MethodCallHandler, StreamHandler, FlutterPlugin {
/** BatteryPlusPlugin */
public class BatteryPlusPlugin implements MethodCallHandler, StreamHandler, FlutterPlugin {

private Context applicationContext;
private BroadcastReceiver chargingStateChangeReceiver;
Expand All @@ -33,7 +33,7 @@ public class BatteryPlugin implements MethodCallHandler, StreamHandler, FlutterP

/** Plugin registration. */
public static void registerWith(PluginRegistry.Registrar registrar) {
final BatteryPlugin instance = new BatteryPlugin();
final BatteryPlusPlugin instance = new BatteryPlusPlugin();
instance.onAttachedToEngine(registrar.context(), registrar.messenger());
}

Expand All @@ -44,8 +44,8 @@ public void onAttachedToEngine(FlutterPluginBinding binding) {

private void onAttachedToEngine(Context applicationContext, BinaryMessenger messenger) {
this.applicationContext = applicationContext;
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/battery");
eventChannel = new EventChannel(messenger, "plugins.flutter.io/charging");
methodChannel = new MethodChannel(messenger, "dev.fluttercommunity.plus/battery");
eventChannel = new EventChannel(messenger, "dev.fluttercommunity.plus/charging");
eventChannel.setStreamHandler(this);
methodChannel.setMethodCallHandler(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

#import <Flutter/Flutter.h>

@interface FLTBatteryPlugin : NSObject <FlutterPlugin>
@interface FLTBatteryPlusPlugin : NSObject <FlutterPlugin>
@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "FLTBatteryPlugin.h"
#import "FLTBatteryPlusPlugin.h"

@interface FLTBatteryPlugin () <FlutterStreamHandler>
@interface FLTBatteryPlusPlugin () <FlutterStreamHandler>
@end

@implementation FLTBatteryPlugin {
@implementation FLTBatteryPlusPlugin {
FlutterEventSink _eventSink;
}

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FLTBatteryPlugin* instance = [[FLTBatteryPlugin alloc] init];
FLTBatteryPlusPlugin* instance = [[FLTBatteryPlusPlugin alloc] init];

FlutterMethodChannel* channel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/battery"
[FlutterMethodChannel methodChannelWithName:@"dev.fluttercommunity.plus/battery"
binaryMessenger:[registrar messenger]];

[registrar addMethodCallDelegate:instance channel:channel];
FlutterEventChannel* chargingChannel =
[FlutterEventChannel eventChannelWithName:@"plugins.flutter.io/charging"
[FlutterEventChannel eventChannelWithName:@"dev.fluttercommunity.plus/charging"
binaryMessenger:[registrar messenger]];
[chargingChannel setStreamHandler:instance];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/battery_plus/lib/battery_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Battery {
// with a non-default instance.
if (!kIsWeb && BatteryPlatform.instance is MethodChannelBattery) {
if (Platform.isLinux) {
BatteryPlatform.instance = BatteryLinux();
BatteryPlatform.instance = BatteryPlusLinux();
}
}
_manualDartRegistrationNeeded = false;
Expand Down
12 changes: 6 additions & 6 deletions packages/battery_plus/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: battery_plus
description: Flutter plugin for accessing information about the battery state(full, charging, discharging).
version: 0.8.0
version: 0.9.0
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

flutter:
plugin:
platforms:
android:
package: io.flutter.plugins.battery
pluginClass: BatteryPlugin
package: dev.fluttercommunity.plus.battery
pluginClass: BatteryPlusPlugin
ios:
pluginClass: FLTBatteryPlugin
pluginClass: FLTBatteryPlusPlugin
linux:
default_package: battery_plus_linux
macos:
Expand All @@ -25,10 +25,10 @@ dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
battery_plus_platform_interface: ^0.1.0
battery_plus_platform_interface: ^0.2.0
battery_plus_linux: ^0.1.0
battery_plus_macos: ^0.1.0
battery_plus_web: ^0.1.0
battery_plus_web: ^0.2.0
battery_plus_windows: ^0.1.0

dev_dependencies:
Expand Down
6 changes: 5 additions & 1 deletion packages/battery_plus_linux/lib/battery_plus_linux.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/// The Linux implementation of `battery_plus`.
library battery_plus_linux;

export 'src/battery_linux.dart';
// battery_plus_linux depends on dbus which uses FFI internally; export a stub
// for platforms that don't support FFI (e.g., web) to avoid having transitive
// dependencies break web compilation.
export 'src/battery_plus_linux_stub.dart'
if (dart.library.ffi) 'src/battery_plus_linux_real.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension _ToBatteryState on UPowerBatteryState {
typedef UPowerDeviceFactory = UPowerDevice Function();

/// The Linux implementation of BatteryPlatform.
class BatteryLinux extends BatteryPlatform {
class BatteryPlusLinux extends BatteryPlatform {
/// Returns the current battery level in percent.
@override
Future<int> get batteryLevel {
Expand Down
15 changes: 15 additions & 0 deletions packages/battery_plus_linux/lib/src/battery_plus_linux_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:battery_plus_platform_interface/battery_plus_platform_interface.dart';

/// A stub implementation to satisfy compilation of multi-platform packages that
/// depend on battery_plus_linux. This should never actually be created.
///
/// Notably, because battery_plus needs to manually register battery_plus_linux,
/// anything with a transitive dependency on battery_plus will also depend on
/// battery_plus_linux, not just at the pubspec level but the code level.
class BatteryPlusLinux extends BatteryPlatform {
/// Errors on attempted instantiation of the stub. It exists only to satisfy
/// compile-time dependencies, and should never actually be created.
BatteryPlusLinux() {
assert(false);
}
}
4 changes: 2 additions & 2 deletions packages/battery_plus_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ version: 0.1.0

environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.17.0 <2.0.0"
flutter: ">=1.20.0"

dependencies:
battery_plus_platform_interface: ^0.1.0
battery_plus_platform_interface: ^0.2.0
dbus: ^0.1.0
flutter:
sdk: flutter
Expand Down
6 changes: 3 additions & 3 deletions packages/battery_plus_linux/test/battery_plus_linux_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:battery_plus_linux/src/battery_linux.dart';
import 'package:battery_plus_linux/src/battery_plus_linux_real.dart';
import 'package:battery_plus_linux/src/upower_device.dart';
import 'package:battery_plus_platform_interface/battery_plus_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -8,7 +8,7 @@ class MockDevice extends Mock implements UPowerDevice {}

void main() {
test('battery level', () async {
final battery = BatteryLinux();
final battery = BatteryPlusLinux();
battery.createDevice = () {
final device = MockDevice();
when(device.getPercentage()).thenAnswer((_) => Future.value(56.78));
Expand All @@ -18,7 +18,7 @@ void main() {
});

test('battery state changes', () {
final battery = BatteryLinux();
final battery = BatteryPlusLinux();
battery.createDevice = () {
final device = MockDevice();
when(device.getState()).thenAnswer((_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import IOKit.ps

public class BatteryPlusMacosPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "plugins.flutter.io/battery", binaryMessenger: registrar.messenger)
let channel = FlutterMethodChannel(name: "dev.fluttercommunity.plus/battery", binaryMessenger: registrar.messenger)

let eventChannel = FlutterEventChannel(name: "plugins.flutter.io/charging", binaryMessenger: registrar.messenger)
let eventChannel = FlutterEventChannel(name: "dev.fluttercommunity.plus/charging", binaryMessenger: registrar.messenger)

let instance = BatteryPlusMacosPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
Expand Down
4 changes: 2 additions & 2 deletions packages/battery_plus_macos/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ version: 0.1.0

environment:
sdk: '>=2.6.0 <3.0.0'
flutter: '>=1.12.13+hotfix.4'
flutter: '>=1.20.0'

dependencies:
battery_plus_platform_interface: ^0.1.0
battery_plus_platform_interface: ^0.2.0
flutter:
sdk: flutter

Expand Down
4 changes: 4 additions & 0 deletions packages/battery_plus_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0

- Rename method channel to avoid conflicts

## 0.1.0

- Transfer to plus-plugins monorepo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import 'utils.dart';
class MethodChannelBattery extends BatteryPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
MethodChannel methodChannel = MethodChannel('plugins.flutter.io/battery');
MethodChannel methodChannel =
MethodChannel('dev.fluttercommunity.plus/battery');

/// The event channel used to receive BatteryState changes from the native platform.
@visibleForTesting
EventChannel eventChannel = EventChannel('plugins.flutter.io/charging');
EventChannel eventChannel =
EventChannel('dev.fluttercommunity.plus/charging');

Stream<BatteryState> _onBatteryStateChanged;

Expand Down
2 changes: 1 addition & 1 deletion packages/battery_plus_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: battery_plus_platform_interface
description: A common platform interface for the battery_plus plugin.
version: 0.1.0
version: 0.2.0
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

Expand Down
4 changes: 4 additions & 0 deletions packages/battery_plus_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0

- Rename method channel to avoid conflicts

## 0.1.0

- Transfer to plus-plugins monorepo
Expand Down
9 changes: 5 additions & 4 deletions packages/battery_plus_web/lib/battery_plus_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import 'package:battery_plus_platform_interface/battery_plus_platform_interface.
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

/// The web implementation of the BatteryPlatform of the Battery plugin.
class BatteryPlugin extends BatteryPlatform {
/// Constructs a BatteryPlugin.
BatteryPlugin(html.Navigator navigator) : _getBattery = navigator.getBattery;
class BatteryPlusPlugin extends BatteryPlatform {
/// Constructs a BatteryPlusPlugin.
BatteryPlusPlugin(html.Navigator navigator)
: _getBattery = navigator.getBattery;

/// A check to determine if this version of the plugin can be used.
bool get isSupported => html.window.navigator.getBattery != null;
Expand All @@ -18,7 +19,7 @@ class BatteryPlugin extends BatteryPlatform {
/// Factory method that initializes the Battery plugin platform with an instance
/// of the plugin for the web.
static void registerWith(Registrar registrar) {
BatteryPlatform.instance = BatteryPlugin(html.window.navigator);
BatteryPlatform.instance = BatteryPlusPlugin(html.window.navigator);
}

/// Checks the connection status of the device.
Expand Down
6 changes: 3 additions & 3 deletions packages/battery_plus_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: battery_plus_web
description: An implementation for the web platform of the Flutter `battery_plus` plugin.
version: 0.1.0
version: 0.2.0
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

flutter:
plugin:
platforms:
web:
pluginClass: BatteryPlugin
pluginClass: BatteryPlusPlugin
fileName: battery_plus_web.dart

dependencies:
battery_plus_platform_interface: ^0.1.0
battery_plus_platform_interface: ^0.2.0
flutter_web_plugins:
sdk: flutter
flutter:
Expand Down
2 changes: 1 addition & 1 deletion packages/battery_plus_windows/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
flutter: ">=1.20.0 <2.0.0"

dependencies:
battery_plus_platform_interface: ^0.1.0
battery_plus_platform_interface: ^0.2.0
flutter:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void BatteryPlusWindowsPlugin::RegisterWithRegistrar(
BatteryPlusWindowsPlugin::BatteryPlusWindowsPlugin(
flutter::PluginRegistrarWindows *registrar) {
auto methodChannel = std::make_unique<FlMethodChannel>(
registrar->messenger(), "plugins.flutter.io/battery",
registrar->messenger(), "dev.fluttercommunity.plus/battery",
&flutter::StandardMethodCodec::GetInstance());

methodChannel->SetMethodCallHandler(
Expand All @@ -73,7 +73,7 @@ BatteryPlusWindowsPlugin::BatteryPlusWindowsPlugin(
});

auto eventChannel = std::make_unique<FlEventChannel>(
registrar->messenger(), "plugins.flutter.io/charging",
registrar->messenger(), "dev.fluttercommunity.plus/charging",
&flutter::StandardMethodCodec::GetInstance());

eventChannel->SetStreamHandler(
Expand Down