Merge pull request #1402 from Kingtous/master

fix: close all typed sessions when hide subwindow
This commit is contained in:
RustDesk 2022-08-30 21:00:45 +08:00 committed by GitHub
commit 256149ecdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 27 deletions

View File

@ -63,7 +63,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
label: id, label: id,
selectedIcon: selectedIcon, selectedIcon: selectedIcon,
unselectedIcon: unselectedIcon, unselectedIcon: unselectedIcon,
closable: false,
page: Obx(() => RemotePage( page: Obx(() => RemotePage(
key: ValueKey(id), key: ValueKey(id),
id: id, id: id,
@ -71,7 +70,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight, fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
)))); ))));
} else if (call.method == "onDestroy") { } else if (call.method == "onDestroy") {
tabController.state.value.tabs.clear(); tabController.clear();
} }
}); });
} }
@ -93,6 +92,9 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
theme: theme, theme: theme,
isMainWindow: false, isMainWindow: false,
showTabBar: fullscreen.isFalse, showTabBar: fullscreen.isFalse,
onClose: () {
tabController.clear();
},
tail: AddButton( tail: AddButton(
theme: theme, theme: theme,
).paddingOnly(left: 10), ).paddingOnly(left: 10),

View File

@ -19,12 +19,13 @@ class FileManagerTabPage extends StatefulWidget {
} }
class _FileManagerTabPageState extends State<FileManagerTabPage> { class _FileManagerTabPageState extends State<FileManagerTabPage> {
final tabController = Get.put(DesktopTabController()); DesktopTabController get tabController => Get.find<DesktopTabController>();
static final IconData selectedIcon = Icons.file_copy_sharp; static final IconData selectedIcon = Icons.file_copy_sharp;
static final IconData unselectedIcon = Icons.file_copy_outlined; static final IconData unselectedIcon = Icons.file_copy_outlined;
_FileManagerTabPageState(Map<String, dynamic> params) { _FileManagerTabPageState(Map<String, dynamic> params) {
Get.put(DesktopTabController());
tabController.add(TabInfo( tabController.add(TabInfo(
key: params['id'], key: params['id'],
label: params['id'], label: params['id'],
@ -54,7 +55,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
unselectedIcon: unselectedIcon, unselectedIcon: unselectedIcon,
page: FileManagerPage(key: ValueKey(id), id: id))); page: FileManagerPage(key: ValueKey(id), id: id)));
} else if (call.method == "onDestroy") { } else if (call.method == "onDestroy") {
tabController.state.value.tabs.clear(); tabController.clear();
} }
}); });
} }
@ -74,6 +75,9 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
controller: tabController, controller: tabController,
theme: theme, theme: theme,
isMainWindow: false, isMainWindow: false,
onClose: () {
tabController.clear();
},
tail: AddButton( tail: AddButton(
theme: theme, theme: theme,
).paddingOnly(left: 10), ).paddingOnly(left: 10),

View File

@ -58,7 +58,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
unselectedIcon: unselectedIcon, unselectedIcon: unselectedIcon,
page: PortForwardPage(id: id, isRDP: isRDP))); page: PortForwardPage(id: id, isRDP: isRDP)));
} else if (call.method == "onDestroy") { } else if (call.method == "onDestroy") {
tabController.state.value.tabs.clear(); tabController.clear();
} }
}); });
} }
@ -77,6 +77,9 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
controller: tabController, controller: tabController,
theme: theme, theme: theme,
isMainWindow: false, isMainWindow: false,
onClose: () {
tabController.clear();
},
tail: AddButton( tail: AddButton(
theme: theme, theme: theme,
).paddingOnly(left: 10), ).paddingOnly(left: 10),

View File

@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'package:desktop_multi_window/desktop_multi_window.dart'; import 'package:desktop_multi_window/desktop_multi_window.dart';
@ -113,6 +114,11 @@ class DesktopTabController {
remove(state.value.selected); remove(state.value.selected);
} }
} }
void clear() {
state.value.tabs.clear();
state.refresh();
}
} }
class DesktopTab extends StatelessWidget { class DesktopTab extends StatelessWidget {
@ -127,11 +133,12 @@ class DesktopTab extends StatelessWidget {
final bool showClose; final bool showClose;
final Widget Function(Widget pageView)? pageViewBuilder; final Widget Function(Widget pageView)? pageViewBuilder;
final Widget? tail; final Widget? tail;
final VoidCallback? onClose;
final DesktopTabController controller; final DesktopTabController controller;
late final state = controller.state; Rx<DesktopTabState> get state => controller.state;
DesktopTab( const DesktopTab(
{required this.controller, {required this.controller,
required this.isMainWindow, required this.isMainWindow,
this.theme = const TarBarTheme.light(), this.theme = const TarBarTheme.light(),
@ -143,7 +150,8 @@ class DesktopTab extends StatelessWidget {
this.showMaximize = true, this.showMaximize = true,
this.showClose = true, this.showClose = true,
this.pageViewBuilder, this.pageViewBuilder,
this.tail}); this.tail,
this.onClose});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -185,6 +193,9 @@ class DesktopTab extends StatelessWidget {
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
Offstage(
offstage: !Platform.isMacOS,
child: const SizedBox(width: 78,)),
Row(children: [ Row(children: [
Offstage( Offstage(
offstage: !showLogo, offstage: !showLogo,
@ -229,6 +240,7 @@ class DesktopTab extends StatelessWidget {
showMinimize: showMinimize, showMinimize: showMinimize,
showMaximize: showMaximize, showMaximize: showMaximize,
showClose: showClose, showClose: showClose,
onClose: onClose,
) )
], ],
); );
@ -242,6 +254,7 @@ class WindowActionPanel extends StatelessWidget {
final bool showMinimize; final bool showMinimize;
final bool showMaximize; final bool showMaximize;
final bool showClose; final bool showClose;
final VoidCallback? onClose;
const WindowActionPanel( const WindowActionPanel(
{Key? key, {Key? key,
@ -249,7 +262,8 @@ class WindowActionPanel extends StatelessWidget {
required this.theme, required this.theme,
this.showMinimize = true, this.showMinimize = true,
this.showMaximize = true, this.showMaximize = true,
this.showClose = true}) this.showClose = true,
this.onClose})
: super(key: key); : super(key: key);
@override @override
@ -324,8 +338,11 @@ class WindowActionPanel extends StatelessWidget {
windowManager.close(); windowManager.close();
} else { } else {
// only hide for multi window, not close // only hide for multi window, not close
Future.delayed(Duration.zero, () {
WindowController.fromWindowId(windowId!).hide(); WindowController.fromWindowId(windowId!).hide();
});
} }
onClose?.call();
}, },
is_close: true, is_close: true,
)), )),
@ -337,13 +354,12 @@ class WindowActionPanel extends StatelessWidget {
// ignore: must_be_immutable // ignore: must_be_immutable
class _ListView extends StatelessWidget { class _ListView extends StatelessWidget {
final DesktopTabController controller; final DesktopTabController controller;
late final Rx<DesktopTabState> state;
final Function(String key)? onTabClose; final Function(String key)? onTabClose;
final TarBarTheme theme; final TarBarTheme theme;
Rx<DesktopTabState> get state => controller.state;
_ListView( const _ListView(
{required this.controller, required this.onTabClose, required this.theme}) {required this.controller, required this.onTabClose, required this.theme});
: this.state = controller.state;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -80,14 +80,7 @@ Future<void> initEnv(String appType) async {
} }
void runMainApp(bool startService) async { void runMainApp(bool startService) async {
WindowOptions windowOptions = getHiddenTitleBarWindowOptions(Size(1280, 720)); await initEnv(kAppTypeMain);
await Future.wait([
initEnv(kAppTypeMain),
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
})
]);
if (startService) { if (startService) {
// await windowManager.ensureInitialized(); // await windowManager.ensureInitialized();
// disable tray // disable tray
@ -95,6 +88,12 @@ void runMainApp(bool startService) async {
gFFI.serverModel.startService(); gFFI.serverModel.startService();
} }
runApp(App()); 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 { void runMobileApp() async {

View File

@ -117,7 +117,7 @@ class PlatformFFI {
_homeDir = (await getDownloadsDirectory())?.path ?? ""; _homeDir = (await getDownloadsDirectory())?.path ?? "";
} }
} catch (e) { } catch (e) {
print(e); print("initialize failed: $e");
} }
String id = 'NA'; String id = 'NA';
String name = 'Flutter'; String name = 'Flutter';
@ -151,7 +151,7 @@ class PlatformFFI {
await _ffiBind.mainSetHomeDir(home: _homeDir); await _ffiBind.mainSetHomeDir(home: _homeDir);
await _ffiBind.mainInit(appDir: _dir); await _ffiBind.mainInit(appDir: _dir);
} catch (e) { } catch (e) {
print(e); print("initialize failed: $e");
} }
version = await getVersion(); version = await getVersion();
} }

View File

@ -163,7 +163,7 @@ class RustDeskMultiWindowManager {
// no such window already // no such window already
return; return;
} }
await WindowController.fromWindowId(wId).hide(); await WindowController.fromWindowId(wId).close();
} on Error { } on Error {
return; return;
} }

View File

@ -34,7 +34,7 @@ dependencies:
provider: ^6.0.3 provider: ^6.0.3
tuple: ^2.0.0 tuple: ^2.0.0
wakelock: ^0.5.2 wakelock: ^0.5.2
device_info_plus: ^4.0.2 device_info_plus: ^4.1.2
firebase_analytics: ^9.1.5 firebase_analytics: ^9.1.5
package_info_plus: ^1.4.2 package_info_plus: ^1.4.2
url_launcher: ^6.0.9 url_launcher: ^6.0.9