diff --git a/flutter/lib/desktop/pages/file_manager_tab_page.dart b/flutter/lib/desktop/pages/file_manager_tab_page.dart index 42c50b927..de874b42d 100644 --- a/flutter/lib/desktop/pages/file_manager_tab_page.dart +++ b/flutter/lib/desktop/pages/file_manager_tab_page.dart @@ -75,9 +75,7 @@ class _FileManagerTabPageState extends State { backgroundColor: MyTheme.color(context).bg, body: DesktopTab( controller: tabController, - onWindowCloseButton: () { - tabController.clear(); - }, + onWindowCloseButton: handleWindowCloseButton, tail: const AddButton().paddingOnly(left: 10), )), ), @@ -103,4 +101,21 @@ class _FileManagerTabPageState extends State { tabController.closeBy(peerId); } } + + Future handleWindowCloseButton() async { + final connLength = tabController.state.value.tabs.length; + if (connLength < 1) { + return true; + } else if (connLength == 1) { + final currentConn = tabController.state.value.tabs[0]; + handleTabCloseButton(currentConn.key); + return false; + } else { + final res = await closeConfirmDialog(); + if (res) { + tabController.clear(); + } + return res; + } + } } diff --git a/flutter/lib/desktop/pages/port_forward_tab_page.dart b/flutter/lib/desktop/pages/port_forward_tab_page.dart index 5dd69e8eb..dffe7856b 100644 --- a/flutter/lib/desktop/pages/port_forward_tab_page.dart +++ b/flutter/lib/desktop/pages/port_forward_tab_page.dart @@ -78,8 +78,9 @@ class _PortForwardTabPageState extends State { backgroundColor: MyTheme.color(context).bg, body: DesktopTab( controller: tabController, - onWindowCloseButton: () { + onWindowCloseButton: () async { tabController.clear(); + return true; }, tail: AddButton().paddingOnly(left: 10), )), diff --git a/flutter/lib/desktop/pages/remote_tab_page.dart b/flutter/lib/desktop/pages/remote_tab_page.dart index e5caccd71..2f87c51fb 100644 --- a/flutter/lib/desktop/pages/remote_tab_page.dart +++ b/flutter/lib/desktop/pages/remote_tab_page.dart @@ -97,9 +97,7 @@ class _ConnectionTabPageState extends State { body: DesktopTab( controller: tabController, showTabBar: fullscreen.isFalse, - onWindowCloseButton: () { - tabController.clear(); - }, + onWindowCloseButton: handleWindowCloseButton, tail: AddButton().paddingOnly(left: 10), pageViewBuilder: (pageView) { WindowController.fromWindowId(windowId()) @@ -167,4 +165,21 @@ class _ConnectionTabPageState extends State { tabController.closeBy(peerId); } } + + Future handleWindowCloseButton() async { + final connLength = tabController.state.value.tabs.length; + if (connLength < 1) { + return true; + } else if (connLength == 1) { + final currentConn = tabController.state.value.tabs[0]; + handleTabCloseButton(currentConn.key); + return false; + } else { + final res = await closeConfirmDialog(); + if (res) { + tabController.clear(); + } + return res; + } + } } diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index fef5fbf1f..e812b3e7c 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -183,7 +183,7 @@ class DesktopTab extends StatelessWidget { final bool showClose; final Widget Function(Widget pageView)? pageViewBuilder; final Widget? tail; - final VoidCallback? onWindowCloseButton; + final Future Function()? onWindowCloseButton; final TabBuilder? tabBuilder; final LabelGetter? labelGetter; @@ -356,7 +356,7 @@ class WindowActionPanel extends StatelessWidget { final bool showMinimize; final bool showMaximize; final bool showClose; - final VoidCallback? onClose; + final Future Function()? onClose; const WindowActionPanel( {Key? key, @@ -434,7 +434,8 @@ class WindowActionPanel extends StatelessWidget { message: 'Close', icon: IconFont.close, onTap: () async { - action() { + final res = await onClose?.call() ?? true; + if (res) { if (mainTab) { windowManager.close(); } else { @@ -443,14 +444,6 @@ class WindowActionPanel extends StatelessWidget { WindowController.fromWindowId(windowId!).hide(); }); } - onClose?.call(); - } - - if (tabType != DesktopTabType.main && - state.value.tabs.length > 1) { - closeConfirmDialog(action); - } else { - action(); } }, isClose: true, @@ -458,30 +451,28 @@ class WindowActionPanel extends StatelessWidget { ], ); } +} - closeConfirmDialog(Function() callback) async { - final res = await gFFI.dialogManager.show((setState, close) { - submit() => close(true); - return CustomAlertDialog( - title: Row(children: [ - const Icon(Icons.warning_amber_sharp, - color: Colors.redAccent, size: 28), - const SizedBox(width: 10), - Text(translate("Warning")), - ]), - content: Text(translate("Disconnect all devices?")), - actions: [ - TextButton(onPressed: close, child: Text(translate("Cancel"))), - ElevatedButton(onPressed: submit, child: Text(translate("OK"))), - ], - onSubmit: submit, - onCancel: close, - ); - }); - if (res == true) { - callback(); - } - } +Future closeConfirmDialog() async { + final res = await gFFI.dialogManager.show((setState, close) { + submit() => close(true); + return CustomAlertDialog( + title: Row(children: [ + const Icon(Icons.warning_amber_sharp, + color: Colors.redAccent, size: 28), + const SizedBox(width: 10), + Text(translate("Warning")), + ]), + content: Text(translate("Disconnect all devices?")), + actions: [ + TextButton(onPressed: close, child: Text(translate("Cancel"))), + ElevatedButton(onPressed: submit, child: Text(translate("OK"))), + ], + onSubmit: submit, + onCancel: close, + ); + }); + return res == true; } // ignore: must_be_immutable