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

Conversation

@gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Feb 24, 2023

Description

This adds support for System.exitApplication and sending and handling the response from System.requestAppExit to the platform channel.

It also introduces a FlutterApplication class that is a subclass of NSApplication, and overrides the terminate message so that it can ignore it if the framework decides to cancel the termination, and to allow for async communication with the framework before termination.

If the application doesn't use a FlutterApplication as its NSPrincipalClass in Info.plist for the application, then it all works as before: the application will be unable to cancel the request. In debug mode it does log once per run, if the application is accessed, that some capabilities are disabled (like exitApplication). I'm not really sure if we should be doing the log message. It seems like a good prompt to remind people to migrate, and how, but I could easily be convinced that it's log spam.

Paired with flutter/flutter#121378 to enable the framework to respond properly. Before that lands, if anyone switches to use FlutterApplication as their principal class, termination requests will go unanswered.

Related Issues

Tests

  • Adds tests for the round trip from framework request for exit, to application termination request from the engine to framework, and then a response to the engine to actually terminate.

@gspencergoog gspencergoog force-pushed the app_exit branch 2 times, most recently from bdc025a to 41e319e Compare February 27, 2023 23:54
@gspencergoog gspencergoog marked this pull request as ready for review February 27, 2023 23:54
@gspencergoog
Copy link
Contributor Author

gspencergoog commented Feb 28, 2023

Ok, PTAL: I've added a test that goes the round trip: handles a call to exit the application from the framework, asks the framework if that's OK (so that if other listeners are registered, they get asked), and then either exits or doesn't depending on the response. If it had come from the OS, then it would just do the last part (query the framework and then possibly exit).

The only thing I couldn't figure out how to test was the actually call to [[FlutterApplication sharedApplication] terminate:nil], since that requires that there be a real application running (making a mock subclass would just bypass the thing I'm trying to test). There's only a couple of lines of code there.

I was able to cut down the necessary additions to FlutterAppDelegate to be just an internal property that is the termination handler.

The termination handler is an internal class, and so is the property on FlutterAppDelegate for now. I considered making them public, but I'd like to see a use case first.

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.

A couple quick comments before I grab dinner. Will finish the rest of the review in a bit!

@gspencergoog gspencergoog force-pushed the app_exit branch 3 times, most recently from 4daadab to 2d76d62 Compare March 1, 2023 21:32
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!

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 platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants