-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add platform channel System.exitApplication
and System.requestAppExit
support
#39836
Conversation
81c9e94
to
f9e6ee1
Compare
shell/platform/darwin/macos/framework/Headers/FlutterApplication.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate_internal.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm
Outdated
Show resolved
Hide resolved
bdc025a
to
41e319e
Compare
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 I was able to cut down the necessary additions to The termination handler is an internal class, and so is the property on |
8ff0ee5
to
f06fefb
Compare
shell/platform/darwin/macos/framework/Headers/FlutterApplication.h
Outdated
Show resolved
Hide resolved
2076a39
to
0255d98
Compare
shell/platform/darwin/macos/framework/Headers/FlutterApplication.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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!
shell/platform/darwin/macos/framework/Headers/FlutterApplication.h
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterEngineTest.mm
Outdated
Show resolved
Hide resolved
33755cf
to
5bf896f
Compare
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterAppDelegate_Internal.h
Outdated
Show resolved
Hide resolved
4daadab
to
2d76d62
Compare
shell/platform/darwin/macos/framework/Source/FlutterApplication.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterApplication.mm
Outdated
Show resolved
Hide resolved
shell/platform/darwin/macos/framework/Source/FlutterApplication.mm
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
…equestAppExit` support (flutter/engine#39836)
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: flutter#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
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: flutter#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
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: flutter#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
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 No new tests since this refactors existing behaviour while retaining the same app semantics as before.
Description
This adds support for
System.exitApplication
and sending and handling the response fromSystem.requestAppExit
to the platform channel.It also introduces a
FlutterApplication
class that is a subclass ofNSApplication
, and overrides theterminate
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 itsNSPrincipalClass
inInfo.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