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

Conversation

@cbracken
Copy link
Member

@cbracken cbracken commented Apr 4, 2023

Moves application termination handling to FlutterAppDelegate. Previously, we required macOS applications using Flutter to ensure their main application class was FlutterApplication. Instead, we now do all handling in FlutterAppDelegate and FlutterEngine.

There are two termination workflows to consider:

  • Termination requested from framework side: In this case, then engine receives a System.exitApplication method call, and starts the app termination workflow via [FlutterEngine requestApplicationTermination:exitType:result].
  • Termination requested from macOS (e.g. Cmd-Q): In this case, FlutterAppDelegate's applicationShouldTerminate: handler is invoked by AppKit, and the delegate starts the app termination workflow via [FlutterEngine requestApplicationTermination:exitType:result].

In either case, at this point, if the request is not cancellable, the app immediately exits. If it is cancellable, the embedder sends a System.requestAppExit method channel invocation to the framework, which responds with either exit or cancel. In the case of exit we immediately exit, otherwise we do nothing and the app continues running.

This is a minor refactoring of the original approach we took in: #39836

Removal of FlutterApplication will happen in three steps:

  1. Migrate logic to FlutterAppDelegate. [macOS] Handle termination in FlutterAppDelegate #40929.
  2. Update Flutter tool template. Update migrator to migrate all apps using FlutterApplication back to NSApplication. [macOS] Remigrate principal class to NSApplication flutter#124173.
  3. Eliminate FlutterApplication.h header since all references to it have now been removed. [macOS] Remove FlutterApplication class #40939.

Issue: flutter/flutter#30735

No new tests since this refactors existing behaviour while retaining the same app semantics as before.

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Moves application termination handling to FlutterAppDelegate.
Previously, we required macOS applications using Flutter to ensure their
main application class was FlutterApplication. Instead, we now do all
handling in FlutterAppDelegate and FlutterEngine.

There are two termination workflows to consider:
* Termination requested from framework side: In this case, then engine
  receives a `System.exitApplication` method call, and starts the app
  termination workflow via
  `[FlutterEngine requestApplicationTermination:exitType:result]`.
* Termination requested from macOS (e.g. Cmd-Q): In this case,
  `FlutterAppDelegate`'s `applicationShouldTerminate:` handler is
  invoked by AppKit, and the delegate starts the app termination
  workflow via
  `[FlutterEngine requestApplicationTermination:exitType:result]`.

In either case, at this point, if the request is not cancellable, the
app immediately exits. If it is cancellable, the embedder sends a
`System.requestAppExit` method channel invocation to the framework,
which responds with either `exit` or `cancel`. In the case of `exit` we
immediately exit, otherwise we do nothing and the app continues running.

This is a minor refactoring of the original approach we took in:
#39836

This does not remove the FlutterApplication class, since the framework
migration from NSApplication to FlutterApplication still depends on it.
A followup patch with replace the migration with a reverse migration
will land, then FlutterApplication will be removed.

Issue: flutter/flutter#30735
@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 5, 2023
cbracken added a commit to cbracken/flutter that referenced this pull request Apr 5, 2023
In flutter#122336 we migrated the principal class from NSApplication to
FlutterApplication in the app Info.plist. We removed the need for
FlutterApplicaiton in flutter/engine#40929. This
reverses the migration for anyone who previously upgraded on the Flutter
master branch.

Issue: flutter#30735
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #40929 at sha d7d60b4

@cbracken cbracken merged commit 8679b67 into flutter:main Apr 5, 2023
@cbracken cbracken deleted the termination-in-appdelegate branch April 5, 2023 05:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 5, 2023
CaseyHillers pushed a commit to flutter/flutter that referenced this pull request Apr 5, 2023
…124200)

flutter/engine@4219c72...db23c3f

2023-04-05 [email protected] [Impeller] Snap glyph positions to screen
space pixels and map UVs correctly (flutter/engine#40912)
2023-04-05 [email protected] [macOS] Handle termination in
FlutterAppDelegate (flutter/engine#40929)
2023-04-05 [email protected] Manual roll Dart SDK from
f97b9d9b2f64 to beff36793081 (1 revision) (flutter/engine#40934)
2023-04-05 [email protected] Revert "[web] remove obsolete object
caches; simplify native object management" (flutter/engine#40937)

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
cbracken added a commit to flutter/flutter that referenced this pull request Apr 5, 2023
In #122336 we migrated the principal class from NSApplication to
FlutterApplication in the app Info.plist. We removed the need for
FlutterApplication in flutter/engine#40929. This
reverses the migration for anyone who previously upgraded on the Flutter
master branch.

Issue: #30735

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
…lutter#124200)

flutter/engine@4219c72...db23c3f

2023-04-05 [email protected] [Impeller] Snap glyph positions to screen
space pixels and map UVs correctly (flutter/engine#40912)
2023-04-05 [email protected] [macOS] Handle termination in
FlutterAppDelegate (flutter/engine#40929)
2023-04-05 [email protected] Manual roll Dart SDK from
f97b9d9b2f64 to beff36793081 (1 revision) (flutter/engine#40934)
2023-04-05 [email protected] Revert "[web] remove obsolete object
caches; simplify native object management" (flutter/engine#40937)

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
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
In flutter#122336 we migrated the principal class from NSApplication to
FlutterApplication in the app Info.plist. We removed the need for
FlutterApplication in flutter/engine#40929. This
reverses the migration for anyone who previously upgraded on the Flutter
master branch.

Issue: flutter#30735

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-macos will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants