Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(battery_plus)!: platform implementation refactor into a single package #1169

Merged
merged 29 commits into from Oct 8, 2022

Conversation

miquelbeltran
Copy link
Member

@miquelbeltran miquelbeltran commented Oct 5, 2022

Description

After multiple discussions of the maintainer team, we came to the conclusion that maintaining a federated plugin architecture was more painful than brought any advantages.

This PR includes the work to "unfederate" battery_plus.

I decided to pick this package since there are no open PRs targeting this plugin.

Note to reviewers: The PR is easier to see if you checkout the branch.

Work Done

To perform the "unfederation":

  • I moved all code from the respective plugins into the main battery_plus plugin.
  • Then, I renamed all references to the external plugins to the main one, e.g. battery_plus_linux became battery_plus.
  • Also, updated the references to the paths to be local to the package.
  • Some unit tests that existed on the platform packages were moved.
  • The package_interface package also suffered the same fate as the other platform plugins and the code was moved to the main plugin. The platform interface still exists and could theoretically be used by an external plugin that implements a new platform (e.g. Fuchsia?)

Update:

  • battery_plus_package_interface will remain as independent package.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@miquelbeltran miquelbeltran marked this pull request as draft October 5, 2022 19:33
@miquelbeltran
Copy link
Member Author

Windows build is not working, will try to fix tomorrow.

Copy link
Member

@jpnurmi jpnurmi left a comment

Choose a reason for hiding this comment

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

I'm curious, is there a technical reason to have battery_plus_web.dart in lib/ instead of lib/src/?

packages/battery_plus/lib/battery_plus.dart Outdated Show resolved Hide resolved
@miquelbeltran miquelbeltran marked this pull request as ready for review October 6, 2022 05:36
@nohli
Copy link
Member

nohli commented Oct 6, 2022

Yayy the tests are passing 😊

@miquelbeltran
Copy link
Member Author

I'm curious, is there a technical reason to have battery_plus_web.dart in lib/ instead of lib/src/?

This has been addressed ;)

@miquelbeltran
Copy link
Member Author

Yayy the tests are passing blush

I am happy that I didn't need to do any CI changes! Only to make sure that the projects compiled.

I had to switch to my Windows PC to fix the Windows build but that was it.

@nohli
Copy link
Member

nohli commented Oct 6, 2022

The six folders can be deleted, right?
Edit: Nevermind, was only because they contained files not checked into git. Is there maybe a way to delete these folders in local clones although they contain untracked files?

Why is there no linux folder and is pluginClass: none correct?

Screen Shot 2022-10-06 at 08 07 58

Screen Shot 2022-10-06 at 08 08 10

@miquelbeltran
Copy link
Member Author

miquelbeltran commented Oct 6, 2022

The six folders can be deleted, right? Edit: Nevermind, was only because they contained files not checked into git. Is there maybe a way to delete these folders in local clones although they contain untracked files?

The folders will still exist on your local copy, a git clean -dxf will take care of that for you.

Why is there no linux folder and is pluginClass: none correct?

I believe so, since the Linux implementation is purely in Dart. The pluginClass: none existed in the battery_plus_linux pubspec so I copied it over. I am not 100% sure if it is required or not.

@jpnurmi
Copy link
Member

jpnurmi commented Oct 6, 2022

I believe so, since the Linux implementation is purely in Dart. The pluginClass: none existed in the battery_plus_linux pubspec so I copied it over. I am not 100% sure if it is required or not.

It was a temporary workaround that is probably not needed anymore: flutter/flutter#57497

@nohli
Copy link
Member

nohli commented Oct 6, 2022

How about moving everything into src folder?
And perhaps renaming method_channel_battery_plus.dart to battery_plus_method_channel.dart?

Edit: Do we need the platform interface in the lib folder (not in src)?

Screen Shot 2022-10-06 at 08 33 53

@jpnurmi
Copy link
Member

jpnurmi commented Oct 6, 2022

One more, is it possible to move method_channel_battery_plus.dart into src/ as well so that we'd only have battery_plus.dart and the platform interface in the root?

EDIT: What @nohli just said above :)

@jpnurmi
Copy link
Member

jpnurmi commented Oct 6, 2022

Very nice! 👍 LGTM but we need Majid's blessing for this...

@miquelbeltran
Copy link
Member Author

Sorry for going back and forth but now that I think of it, having a separate battery_plus_platform_interface.dart at the top level (instead of exporting all of the platform interface) would avoid polluting the usual import with BatteryPlatform.

Right. Also, we can now export the enums.dart directly instead of going through the platform_interface file.

@nohli
Copy link
Member

nohli commented Oct 6, 2022

LGTM! ❤️

Also letting @mhadaily give the approval 🙂


dependencies:
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
battery_plus_platform_interface: 1.2.1
Copy link
Member Author

Choose a reason for hiding this comment

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

as decided, the platform_interface is going to be referenced by exact version, not by "^"

@@ -37,7 +39,7 @@ class Battery {

/// check if device is on battery save mode
///
/// Currently only impemented on Android, IOS and Windows.
/// Currently only implemented on Android, IOS and Windows.
Copy link
Member

Choose a reason for hiding this comment

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

Since we're fixing typos, iOS would be better

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 couldn't let it go, been seeing the typo the whole day 😂

Copy link
Member

Choose a reason for hiding this comment

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

That's the spirit!

@miquelbeltran miquelbeltran changed the title Unfederate battery_plus BREAKING CHANGE: battery_plus platform implementations refactor Oct 6, 2022
@miquelbeltran miquelbeltran changed the title BREAKING CHANGE: battery_plus platform implementations refactor BREAKING CHANGE(battery_plus): platform implementations refactor into a single package Oct 6, 2022
@miquelbeltran miquelbeltran changed the title BREAKING CHANGE(battery_plus): platform implementations refactor into a single package BREAKING CHANGE(battery_plus): platform implementation refactor into a single package Oct 6, 2022
@miquelbeltran
Copy link
Member Author

I wonder if we should modify this CI check:

 Downloading battery_plus_platform_interface 1.2.1...
Package validation found the following potential issue:
* Your dependency on "battery_plus_platform_interface" should allow more than one version. For example:
  
  dependencies:
    battery_plus_platform_interface: ^1.2.1
  
  Constraints that are too tight will make it difficult for people to use your package
  along with other packages that also depend on "battery_plus_platform_interface".

@miquelbeltran miquelbeltran changed the title BREAKING CHANGE(battery_plus): platform implementation refactor into a single package refactor(battery_plus)!: platform implementation refactor into a single package Oct 6, 2022
Copy link
Collaborator

@vbuberen vbuberen left a comment

Choose a reason for hiding this comment

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

Looks good to me

@miquelbeltran miquelbeltran merged commit 143204b into main Oct 8, 2022
@miquelbeltran miquelbeltran deleted the battery_plus_unfederate branch October 8, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants