From 9fee1f41e76f3ae6e6f7107d80aa7d8723e21795 Mon Sep 17 00:00:00 2001
From: Kingtous <kingtous@qq.com>
Date: Thu, 18 Aug 2022 09:51:19 +0800
Subject: [PATCH] opt: use WindowOption to initialize screen

Signed-off-by: Kingtous <kingtous@qq.com>
---
 flutter/lib/main.dart           | 17 ++++++++++++++---
 flutter/linux/my_application.cc |  5 ++---
 flutter/pubspec.yaml            |  1 -
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart
index c767014ea..ef4ec81c8 100644
--- a/flutter/lib/main.dart
+++ b/flutter/lib/main.dart
@@ -117,12 +117,23 @@ void runFileTransferScreen(Map<String, dynamic> argument) async {
 }
 
 void runConnectionManagerScreen() async {
+  // initialize window
+  WindowOptions windowOptions = WindowOptions(
+    size: Size(300, 400),
+    center: true,
+    backgroundColor: Colors.transparent,
+    skipTaskbar: false,
+    titleBarStyle: TitleBarStyle.normal,
+  );
   await Future.wait([
     initEnv(kAppTypeConnectionManager),
-    windowManager
-        .setSize(Size(300, 400))
-        .then((value) => windowManager.setAlignment(Alignment.topRight))
+    windowManager.waitUntilReadyToShow(windowOptions, () async {
+      await windowManager.setAlignment(Alignment.topRight);
+      await windowManager.show();
+      await windowManager.focus();
+    })
   ]);
+  ;
   runApp(GetMaterialApp(theme: getCurrentTheme(), home: DesktopServerPage()));
 }
 
diff --git a/flutter/linux/my_application.cc b/flutter/linux/my_application.cc
index 25e9858cc..20513032d 100644
--- a/flutter/linux/my_application.cc
+++ b/flutter/linux/my_application.cc
@@ -1,7 +1,6 @@
 #include "my_application.h"
 
 #include <flutter_linux/flutter_linux.h>
-// #include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
 #ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
 #endif
@@ -48,8 +47,8 @@ static void my_application_activate(GApplication* application) {
     gtk_window_set_title(window, "rustdesk");
   }
 
-  // auto bdw = bitsdojo_window_from(window);            // <--- add this line
-  // bdw->setCustomFrame(true);                          // <-- add this line
+  // auto bdw = bitsdojo_window_from(window); // <--- add this line
+  // bdw->setCustomFrame(true);               // <-- add this line
   gtk_window_set_default_size(window, 1280, 720);   // <-- comment this line
   gtk_widget_show(GTK_WIDGET(window));
 
diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml
index fcc7b5f49..caa12313d 100644
--- a/flutter/pubspec.yaml
+++ b/flutter/pubspec.yaml
@@ -66,7 +66,6 @@ dependencies:
         git:
             url: https://github.com/Kingtous/rustdesk_desktop_multi_window
             ref: 2b1176d53f195cc55e8d37151bb3d9f6bd52fad3
-    # bitsdojo_window: ^0.1.2
     freezed_annotation: ^2.0.3
     tray_manager: 0.1.7
     get: ^4.6.5