diff --git a/flutter/lib/desktop/pages/connection_tab_page.dart b/flutter/lib/desktop/pages/connection_tab_page.dart index 445590037..1d00cdc8a 100644 --- a/flutter/lib/desktop/pages/connection_tab_page.dart +++ b/flutter/lib/desktop/pages/connection_tab_page.dart @@ -63,7 +63,6 @@ class _ConnectionTabPageState extends State { label: id, selectedIcon: selectedIcon, unselectedIcon: unselectedIcon, - closable: false, page: Obx(() => RemotePage( key: ValueKey(id), id: id, @@ -71,7 +70,7 @@ class _ConnectionTabPageState extends State { fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, )))); } else if (call.method == "onDestroy") { - tabController.state.value.tabs.clear(); + tabController.clear(); } }); } @@ -93,6 +92,9 @@ class _ConnectionTabPageState extends State { theme: theme, isMainWindow: false, showTabBar: fullscreen.isFalse, + onClose: () { + tabController.clear(); + }, tail: AddButton( theme: theme, ).paddingOnly(left: 10), diff --git a/flutter/lib/desktop/pages/file_manager_tab_page.dart b/flutter/lib/desktop/pages/file_manager_tab_page.dart index e391afd71..e7f08a516 100644 --- a/flutter/lib/desktop/pages/file_manager_tab_page.dart +++ b/flutter/lib/desktop/pages/file_manager_tab_page.dart @@ -19,12 +19,13 @@ class FileManagerTabPage extends StatefulWidget { } class _FileManagerTabPageState extends State { - final tabController = Get.put(DesktopTabController()); + DesktopTabController get tabController => Get.find(); static final IconData selectedIcon = Icons.file_copy_sharp; static final IconData unselectedIcon = Icons.file_copy_outlined; _FileManagerTabPageState(Map params) { + Get.put(DesktopTabController()); tabController.add(TabInfo( key: params['id'], label: params['id'], @@ -36,7 +37,7 @@ class _FileManagerTabPageState extends State { @override void initState() { super.initState(); - + tabController.onRemove = (_, id) => onRemoveId(id); rustDeskWinManager.setMethodHandler((call, fromWindowId) async { @@ -54,7 +55,7 @@ class _FileManagerTabPageState extends State { unselectedIcon: unselectedIcon, page: FileManagerPage(key: ValueKey(id), id: id))); } else if (call.method == "onDestroy") { - tabController.state.value.tabs.clear(); + tabController.clear(); } }); } @@ -74,6 +75,9 @@ class _FileManagerTabPageState extends State { controller: tabController, theme: theme, isMainWindow: false, + onClose: () { + tabController.clear(); + }, tail: AddButton( theme: theme, ).paddingOnly(left: 10), diff --git a/flutter/lib/desktop/pages/port_forward_tab_page.dart b/flutter/lib/desktop/pages/port_forward_tab_page.dart index 7555d9745..8db4c7f98 100644 --- a/flutter/lib/desktop/pages/port_forward_tab_page.dart +++ b/flutter/lib/desktop/pages/port_forward_tab_page.dart @@ -58,7 +58,7 @@ class _PortForwardTabPageState extends State { unselectedIcon: unselectedIcon, page: PortForwardPage(id: id, isRDP: isRDP))); } else if (call.method == "onDestroy") { - tabController.state.value.tabs.clear(); + tabController.clear(); } }); } @@ -77,6 +77,9 @@ class _PortForwardTabPageState extends State { controller: tabController, theme: theme, isMainWindow: false, + onClose: () { + tabController.clear(); + }, tail: AddButton( theme: theme, ).paddingOnly(left: 10), diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index b126ca7e3..8ef082b49 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:math'; import 'package:desktop_multi_window/desktop_multi_window.dart'; @@ -113,6 +114,11 @@ class DesktopTabController { remove(state.value.selected); } } + + void clear() { + state.value.tabs.clear(); + state.refresh(); + } } class DesktopTab extends StatelessWidget { @@ -127,11 +133,12 @@ class DesktopTab extends StatelessWidget { final bool showClose; final Widget Function(Widget pageView)? pageViewBuilder; final Widget? tail; + final VoidCallback? onClose; final DesktopTabController controller; - late final state = controller.state; + Rx get state => controller.state; - DesktopTab( + const DesktopTab( {required this.controller, required this.isMainWindow, this.theme = const TarBarTheme.light(), @@ -143,7 +150,8 @@ class DesktopTab extends StatelessWidget { this.showMaximize = true, this.showClose = true, this.pageViewBuilder, - this.tail}); + this.tail, + this.onClose}); @override Widget build(BuildContext context) { @@ -185,6 +193,9 @@ class DesktopTab extends StatelessWidget { Expanded( child: Row( children: [ + Offstage( + offstage: !Platform.isMacOS, + child: const SizedBox(width: 78,)), Row(children: [ Offstage( offstage: !showLogo, @@ -229,6 +240,7 @@ class DesktopTab extends StatelessWidget { showMinimize: showMinimize, showMaximize: showMaximize, showClose: showClose, + onClose: onClose, ) ], ); @@ -242,6 +254,7 @@ class WindowActionPanel extends StatelessWidget { final bool showMinimize; final bool showMaximize; final bool showClose; + final VoidCallback? onClose; const WindowActionPanel( {Key? key, @@ -249,7 +262,8 @@ class WindowActionPanel extends StatelessWidget { required this.theme, this.showMinimize = true, this.showMaximize = true, - this.showClose = true}) + this.showClose = true, + this.onClose}) : super(key: key); @override @@ -324,8 +338,11 @@ class WindowActionPanel extends StatelessWidget { windowManager.close(); } else { // only hide for multi window, not close - WindowController.fromWindowId(windowId!).hide(); + Future.delayed(Duration.zero, () { + WindowController.fromWindowId(windowId!).hide(); + }); } + onClose?.call(); }, is_close: true, )), @@ -337,13 +354,12 @@ class WindowActionPanel extends StatelessWidget { // ignore: must_be_immutable class _ListView extends StatelessWidget { final DesktopTabController controller; - late final Rx state; final Function(String key)? onTabClose; final TarBarTheme theme; + Rx get state => controller.state; - _ListView( - {required this.controller, required this.onTabClose, required this.theme}) - : this.state = controller.state; + const _ListView( + {required this.controller, required this.onTabClose, required this.theme}); @override Widget build(BuildContext context) { diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 401b7febc..da3b07567 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -80,14 +80,7 @@ Future initEnv(String appType) async { } void runMainApp(bool startService) async { - WindowOptions windowOptions = getHiddenTitleBarWindowOptions(Size(1280, 720)); - await Future.wait([ - initEnv(kAppTypeMain), - windowManager.waitUntilReadyToShow(windowOptions, () async { - await windowManager.show(); - await windowManager.focus(); - }) - ]); + await initEnv(kAppTypeMain); if (startService) { // await windowManager.ensureInitialized(); // disable tray @@ -95,6 +88,12 @@ void runMainApp(bool startService) async { gFFI.serverModel.startService(); } runApp(App()); + // set window option + WindowOptions windowOptions = getHiddenTitleBarWindowOptions(const Size(1280, 720)); + windowManager.waitUntilReadyToShow(windowOptions, () async { + await windowManager.show(); + await windowManager.focus(); + }); } void runMobileApp() async { diff --git a/flutter/lib/models/native_model.dart b/flutter/lib/models/native_model.dart index 55f2d0e79..57372cdb9 100644 --- a/flutter/lib/models/native_model.dart +++ b/flutter/lib/models/native_model.dart @@ -117,7 +117,7 @@ class PlatformFFI { _homeDir = (await getDownloadsDirectory())?.path ?? ""; } } catch (e) { - print(e); + print("initialize failed: $e"); } String id = 'NA'; String name = 'Flutter'; @@ -151,7 +151,7 @@ class PlatformFFI { await _ffiBind.mainSetHomeDir(home: _homeDir); await _ffiBind.mainInit(appDir: _dir); } catch (e) { - print(e); + print("initialize failed: $e"); } version = await getVersion(); } diff --git a/flutter/lib/utils/multi_window_manager.dart b/flutter/lib/utils/multi_window_manager.dart index fb6ce11ed..b01b84a9d 100644 --- a/flutter/lib/utils/multi_window_manager.dart +++ b/flutter/lib/utils/multi_window_manager.dart @@ -163,7 +163,7 @@ class RustDeskMultiWindowManager { // no such window already return; } - await WindowController.fromWindowId(wId).hide(); + await WindowController.fromWindowId(wId).close(); } on Error { return; } diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 799a2797a..fc59b8bd3 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -34,7 +34,7 @@ dependencies: provider: ^6.0.3 tuple: ^2.0.0 wakelock: ^0.5.2 - device_info_plus: ^4.0.2 + device_info_plus: ^4.1.2 firebase_analytics: ^9.1.5 package_info_plus: ^1.4.2 url_launcher: ^6.0.9