From 00d3d0f094ef7f79c72cdaf998d3ce97ea5e47a7 Mon Sep 17 00:00:00 2001 From: dignow Date: Wed, 27 Sep 2023 23:51:27 +0800 Subject: [PATCH] fix: cm await call 1. Cm may crash in wrong order. 2. The window may be at the left top. 3. The window may be wrong size. Signed-off-by: dignow --- flutter/lib/main.dart | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 79ef0616d..ef44a3bcc 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -234,19 +234,24 @@ void runConnectionManagerScreen(bool hide) async { listenUniLinks(handleByFlutter: false); } +bool _isCmReadyToShow = false; + showCmWindow({bool isStartup = false}) async { if (isStartup) { WindowOptions windowOptions = getHiddenTitleBarWindowOptions( size: kConnectionManagerWindowSizeClosedChat); - windowManager.waitUntilReadyToShow(windowOptions, () async { - bind.mainHideDocker(); - await windowManager.show(); - await Future.wait([windowManager.focus(), windowManager.setOpacity(1)]); - // ensure initial window size to be changed - await windowManager.setSizeAlignment( - kConnectionManagerWindowSizeClosedChat, Alignment.topRight); - }); - } else { + await windowManager.waitUntilReadyToShow(windowOptions, null); + bind.mainHideDocker(); + await Future.wait([ + windowManager.show(), + windowManager.focus(), + windowManager.setOpacity(1) + ]); + // ensure initial window size to be changed + await windowManager.setSizeAlignment( + kConnectionManagerWindowSizeClosedChat, Alignment.topRight); + _isCmReadyToShow = true; + } else if (_isCmReadyToShow) { if (await windowManager.getOpacity() != 1) { await windowManager.setOpacity(1); await windowManager.focus(); @@ -263,12 +268,12 @@ hideCmWindow({bool isStartup = false}) async { WindowOptions windowOptions = getHiddenTitleBarWindowOptions( size: kConnectionManagerWindowSizeClosedChat); windowManager.setOpacity(0); - windowManager.waitUntilReadyToShow(windowOptions, () async { - bind.mainHideDocker(); - await windowManager.minimize(); - await windowManager.hide(); - }); - } else { + await windowManager.waitUntilReadyToShow(windowOptions, null); + bind.mainHideDocker(); + await windowManager.minimize(); + await windowManager.hide(); + _isCmReadyToShow = true; + } else if (_isCmReadyToShow) { if (await windowManager.getOpacity() != 0) { await windowManager.setOpacity(0); bind.mainHideDocker();