Add a message when a key response takes too long. (flutter/engine#31945)

This splits the nested event loop in the keyboard manager on iOS into two parts: The first times out after 2 seconds, and if that happens, prints an NSLog indicating that the framework took a long time to respond, and then it enters the event loop again, waiting forever this time. This means the behavior doesn't change from what it is now, but will log when things take a long time.
This commit is contained in:
Greg Spencer 2022-03-10 09:59:24 -08:00 committed by GitHub
parent 80ac67970e
commit 0aa006102e

View File

@ -7,6 +7,7 @@
#include "flutter/fml/platform/darwin/message_loop_darwin.h"
static constexpr CFTimeInterval kDistantFuture = 1.0e10;
static constexpr CFTimeInterval kReasonableInterval = 2.0;
@interface FlutterKeyboardManager ()
@ -114,7 +115,14 @@ static constexpr CFTimeInterval kDistantFuture = 1.0e10;
//
// We need to run in this mode so that UIKit doesn't give us new
// events until we are done processing this one.
CFRunLoopRunInMode(fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, kDistantFuture, NO);
CFRunLoopRunResult result = CFRunLoopRunInMode(
fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, kReasonableInterval, NO);
if (result == kCFRunLoopRunTimedOut) {
NSLog(@"Flutter framework failed to process a key event in a reasonable time. Continuing "
@"to wait.");
CFRunLoopRunInMode(fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode, kDistantFuture, NO);
NSLog(@"Flutter framework finally responded. Exiting nested event loop.");
}
break;
}
case UIPressPhaseChanged: