Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add battery plugin #49

Merged
merged 6 commits into from
May 16, 2017
Merged

Add battery plugin #49

merged 6 commits into from
May 16, 2017

Conversation

goderbauer
Copy link
Member

@goderbauer goderbauer changed the title Add bettery plugin Add battery plugin May 15, 2017
@@ -0,0 +1,27 @@
// Copyright 2017 Your Company. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also generally missing copyright header in the .dart|.h|.m|.java files that "links" to this LICENSE file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated.

It's impossible to know which places need updating after running flutter create --plugin :(

A Flutter plugin to access various information about the battery of the device the app is running on.

## Usage
To use this plugin, add url_launcher as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url_launcher?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C&P error :(

@@ -0,0 +1,113 @@
package io.flutter.plugins.battery;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright header in this file

@@ -0,0 +1,45 @@
#include "AppDelegate.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright header

@@ -0,0 +1,87 @@
import 'dart:async';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright header

@@ -0,0 +1,27 @@
// Copyright 2017 Your Company. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also generally missing copyright header in the .dart|.h|.m|.java files that "links" to this LICENSE file

@@ -0,0 +1,70 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is misnamed

@@ -0,0 +1,26 @@
Copyright 2017, the Flutter project authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure this exactly matches https://github.com/flutter/flutter/blob/master/LICENSE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from https://github.com/flutter/plugins/blob/master/LICENSE. Is that one incorrect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to file pointed to by @Hixie.

@goderbauer
Copy link
Member Author

Comments addressed. PTAL.

Copy link
Contributor

@szakarias szakarias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a CHANGELOG.md.

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (void)applicationWillResignActive:(UIApplication *)application {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why you keep the methods below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. I wish we wouldn't generate them in the first place...

battery:
path: ../

# For information on the generic Dart part of this file, see the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the generated comments.

@@ -0,0 +1,20 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have agreed not to maintain this file. We only have it to make CocoaPods happy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's news to me :). Is that documented somewhere? There should probably be a comment on top of this file telling people to just ignore its values.

expect(await battery.batteryLevel, 42);
});

group('battery sate', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sate -> state

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

setUp(() {
methodChannel = new MockMethodChannel();
eventChannel = new MockEventChannel();
battery = new Battery.private(methodChannel, eventChannel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The mockery shouldn't be necessary. In particular, there should be no need to expose channel use from your production code.

Channels are completely stateless objects and don't keep references to their method call handlers. This means you can test every aspect of the communication behavior of Battery just by reusing the channel name in another channel object, created by your test. Then call batteryTestChannel.setMockMethodCallHandler in place of recording mock expectations to test proper calling and result handling for outgoing method calls. Or use BinaryMessages.handlePlatformMessage for simulating incoming events on the event channel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the tests of the url-launcher plugin and compared to that I found the tests with mocking more readable. Also, the EventChannel doesn't seem to provide a similar mechanism for testing, so I would be back to regular mocks anyways?


/// Fires whenever the battery state changes.
Stream<BatteryState> get onBatteryStateChanged {
if (_onBatteryStateChanged == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just make the Stream<BatteryState> a static final field and rely on Dart's lazy initialization of such?

Basically my question is: do we need a Battery object at all?

Maybe we do, to be able to mock it when testing dependent libs. Otherwise those test would have to know about the channel names used in Battery.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do want to keep Battery as its own object to allow app developer to mock it out easily.

Copy link
Member

@mit-mit mit-mit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License changes LGTM

@goderbauer goderbauer merged commit 6a83f6b into flutter:master May 16, 2017
@goderbauer goderbauer deleted the battery branch May 16, 2017 18:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants