From f0be80c253fd964c4bab6e230d6e7a6439fd9170 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:06:23 +0800 Subject: [PATCH] fix: macos, workaround app close (#9880) * fix: macos, workaround app close Signed-off-by: fufesou * Update common.dart --------- Signed-off-by: fufesou Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com> --- flutter/lib/common.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 2b3bcd83c..afec9fa60 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -2498,9 +2498,19 @@ Future onActiveWindowChanged() async { // But the app will not close. // // No idea why we need to delay here, `terminate()` itself is also an async function. - Future.delayed(Duration.zero, () { - RdPlatformChannel.instance.terminate(); - }); + // + // A quick workaround, use `Timer.periodic` to avoid the app not closing. + // Because `await windowManager.close()` and `RdPlatformChannel.instance.terminate()` + // may not work since `Flutter 3.24.4`, see the following logs. + // A delay will allow the app to close. + // + //``` + // embedder.cc (2725): 'FlutterPlatformMessageCreateResponseHandle' returned 'kInvalidArguments'. Engine handle was invalid. + // 2024-11-11 11:41:11.546 RustDesk[90272:2567686] Failed to create a FlutterPlatformMessageResponseHandle (2) + // embedder.cc (2672): 'FlutterEngineSendPlatformMessage' returned 'kInvalidArguments'. Invalid engine handle. + // 2024-11-11 11:41:11.565 RustDesk[90272:2567686] Failed to send message to Flutter engine on channel 'flutter/lifecycle' (2). + // ``` + periodic_immediate(Duration(milliseconds: 30), RdPlatformChannel.instance.terminate); } } }