From 32346c23e0e26af38c8f5b1931b12292224cf639 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Sun, 2 Jun 2024 10:35:54 +0800 Subject: [PATCH] fix: macos, terminate, close main then remote windows (#8240) * fix: macos, terminate, close main then remote windows Signed-off-by: fufesou * comments Signed-off-by: fufesou --------- Signed-off-by: fufesou --- flutter/lib/common.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 7bb338cb4..9741cccf1 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -893,7 +893,7 @@ class OverlayDialogManager { makeMobileActionsOverlayEntry(VoidCallback? onHide, {FFI? ffi}) { final position = SimpleWrapper(Offset(0, 0)); makeMobileActions(BuildContext context, double s) { - final scale = s < 0.85 ? 0.85 : s; + final scale = s < 0.85 ? 0.85 : s; final session = ffi ?? gFFI; // compute overlay position final screenW = MediaQuery.of(context).size.width; @@ -2384,7 +2384,13 @@ Future onActiveWindowChanged() async { await windowManager.setPreventClose(false); await windowManager.close(); if (isMacOS) { - RdPlatformChannel.instance.terminate(); + // If we call without delay, `flutter/macos/Runner/MainFlutterWindow.swift` can handle the "terminate" event. + // 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(); + }); } } }