Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Allow macOS plugins to register as app delegates #44587

Merged
merged 3 commits into from
Aug 11, 2023

Conversation

stuartmorgan-g
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g commented Aug 10, 2023

Adds addApplicationDelegate: to the macOS plugin registrar, following the corresponding iOS method, and wires it up to the existing app delegation forwarding that was recently added for use at the application level. (The actual delegate is non-trivially different between iOS and macOS, but that's not resolveable without a complex migration on the iOS side, so the APIs currently diverge after the level of the addApplicationDelegate: method itself.)

This doesn't add any new methods to the delegation; those will be added in a follow-up PR.

Also fixes a retain cycle in the termination handler that prevented the new test from working.

Most of flutter/flutter#41471

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@stuartmorgan-g
Copy link
Contributor Author

I forgot I still needed to add tests; marking as a draft for now.

Adds `addApplicationDelegate:` to the macOS plugin registrar, following
the corresponding iOS method, and wires it up to the existing app
delegation forwarding that was recently added for use at the application
level. (The actual delegate is non-trivially different between iOS and
macOS, but that's not resolveable without a complex migration on the iOS
side, so the APIs currently diverge after the level of the
`addApplicationDelegate:` method itself.)

This doesn't add any new methods to the delegation; those will be added
in a follow-up PR.

Most of flutter/flutter#41471
@stuartmorgan-g stuartmorgan-g force-pushed the macos-plugin-app-delegate branch from 9865348 to 1edadc3 Compare August 11, 2023 18:36
@stuartmorgan-g stuartmorgan-g marked this pull request as ready for review August 11, 2023 18:43
@stuartmorgan-g
Copy link
Contributor Author

This is now tested and ready for review.

* handlers in FlutterAppLifecycleDelegate to any registered delegates.
*/
FLUTTER_DARWIN_EXPORT
@protocol FlutterAppLifecycleProvider <NSObject>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change isn't strictly necessary, but it makes us match iOS, and it makes the engine code that uses these methods cleaner.

@@ -165,7 +170,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
#pragma mark -

@implementation FlutterEngineTerminationHandler {
FlutterEngine* _engine;
__weak FlutterEngine* _engine;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes a retain cycle that will affect essentially all real-word, non-add-to-app cases (and was breaking my new test).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for spotting this.


- (void)removeApplicationLifecycleDelegate:
(nonnull NSObject<FlutterAppLifecycleDelegate>*)delegate {
auto i = std::find(_delegates.begin(), _delegates.end(), (__bridge void*)delegate);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe delegateIndex for the minor readability benefit given the type is auto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 11, 2023

auto label is removed for flutter/engine/44587, due to - The status or check suite Linux mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2023
@auto-submit auto-submit bot merged commit 832e780 into flutter:main Aug 11, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 11, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 11, 2023
…132407)

flutter/engine@622ded9...832e780

2023-08-11 [email protected] Allow macOS plugins to register as app delegates (flutter/engine#44587)
2023-08-11 [email protected] Roll Skia from 68ea92de8f29 to 7dd695d828cf (1 revision) (flutter/engine#44643)
2023-08-11 [email protected] Roll Dart SDK from 83f96a990792 to ade04f1beb2c (1 revision) (flutter/engine#44642)
2023-08-11 [email protected] Roll Skia from fa30af9c2b80 to 68ea92de8f29 (2 revisions) (flutter/engine#44641)
2023-08-11 [email protected] [Impeller] Added benchmark for advanced blend. (flutter/engine#44450)
2023-08-11 [email protected] [Embedder] Refactor how semantic updates are mapped (flutter/engine#44553)
2023-08-11 [email protected] Roll Skia from cfb9844091fa to fa30af9c2b80 (1 revision) (flutter/engine#44639)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
Adds `addApplicationDelegate:` to the macOS plugin registrar, following the corresponding iOS method, and wires it up to the existing app delegation forwarding that was recently added for use at the application level. (The actual delegate is non-trivially different between iOS and macOS, but that's not resolveable without a complex migration on the iOS side, so the APIs currently diverge after the level of the `addApplicationDelegate:` method itself.)

This doesn't add any new methods to the delegation; those will be added in a follow-up PR.

Also fixes a retain cycle in the termination handler that prevented the new test from working.

Most of flutter/flutter#41471

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-ios platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants