| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | import 'dart:convert'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 16:37:11 +08:00
										 |  |  | import 'package:desktop_multi_window/desktop_multi_window.dart'; | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2022-06-28 22:04:10 +08:00
										 |  |  | import 'package:flutter_hbb/common.dart'; | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | import 'package:flutter_hbb/desktop/pages/file_manager_page.dart'; | 
					
						
							| 
									
										
										
										
											2022-08-06 17:08:48 +08:00
										 |  |  | import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart'; | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | import 'package:flutter_hbb/utils/multi_window_manager.dart'; | 
					
						
							| 
									
										
										
										
											2022-06-27 16:44:34 +08:00
										 |  |  | import 'package:get/get.dart'; | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /// File Transfer for multi tabs
 | 
					
						
							|  |  |  | class FileManagerTabPage extends StatefulWidget { | 
					
						
							|  |  |  |   final Map<String, dynamic> params; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const FileManagerTabPage({Key? key, required this.params}) : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<FileManagerTabPage> createState() => _FileManagerTabPageState(params); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-18 10:54:09 +08:00
										 |  |  | class _FileManagerTabPageState extends State<FileManagerTabPage> { | 
					
						
							| 
									
										
										
										
											2022-08-30 20:48:03 +08:00
										 |  |  |   DesktopTabController get tabController => Get.find<DesktopTabController>(); | 
					
						
							| 
									
										
										
										
											2022-08-24 21:09:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   static final IconData selectedIcon = Icons.file_copy_sharp; | 
					
						
							|  |  |  |   static final IconData unselectedIcon = Icons.file_copy_outlined; | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   _FileManagerTabPageState(Map<String, dynamic> params) { | 
					
						
							| 
									
										
										
										
											2022-08-30 20:48:03 +08:00
										 |  |  |     Get.put(DesktopTabController()); | 
					
						
							| 
									
										
										
										
											2022-08-26 12:14:14 +08:00
										 |  |  |     tabController.add(TabInfo( | 
					
						
							| 
									
										
										
										
											2022-08-24 21:09:18 +08:00
										 |  |  |         key: params['id'], | 
					
						
							|  |  |  |         label: params['id'], | 
					
						
							|  |  |  |         selectedIcon: selectedIcon, | 
					
						
							|  |  |  |         unselectedIcon: unselectedIcon, | 
					
						
							| 
									
										
										
										
											2022-08-26 12:14:14 +08:00
										 |  |  |         page: FileManagerPage(key: ValueKey(params['id']), id: params['id']))); | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							| 
									
										
										
										
											2022-08-30 16:50:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-24 21:09:18 +08:00
										 |  |  |     tabController.onRemove = (_, id) => onRemoveId(id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  |     rustDeskWinManager.setMethodHandler((call, fromWindowId) async { | 
					
						
							|  |  |  |       print( | 
					
						
							| 
									
										
										
										
											2022-08-30 16:45:47 +08:00
										 |  |  |           "call ${call.method} with args ${call.arguments} from window ${fromWindowId} to ${windowId()}"); | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  |       // for simplify, just replace connectionId
 | 
					
						
							|  |  |  |       if (call.method == "new_file_transfer") { | 
					
						
							| 
									
										
										
										
											2022-06-27 16:44:34 +08:00
										 |  |  |         final args = jsonDecode(call.arguments); | 
					
						
							|  |  |  |         final id = args['id']; | 
					
						
							| 
									
										
										
										
											2022-08-09 19:32:19 +08:00
										 |  |  |         window_on_top(windowId()); | 
					
						
							| 
									
										
										
										
											2022-08-24 21:09:18 +08:00
										 |  |  |         tabController.add(TabInfo( | 
					
						
							|  |  |  |             key: id, | 
					
						
							|  |  |  |             label: id, | 
					
						
							|  |  |  |             selectedIcon: selectedIcon, | 
					
						
							|  |  |  |             unselectedIcon: unselectedIcon, | 
					
						
							| 
									
										
										
										
											2022-08-26 12:14:14 +08:00
										 |  |  |             page: FileManagerPage(key: ValueKey(id), id: id))); | 
					
						
							| 
									
										
										
										
											2022-06-28 22:04:10 +08:00
										 |  |  |       } else if (call.method == "onDestroy") { | 
					
						
							| 
									
										
										
										
											2022-08-30 20:48:03 +08:00
										 |  |  |         tabController.clear(); | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2022-08-30 16:45:47 +08:00
										 |  |  |     final theme = | 
					
						
							|  |  |  |         isDarkTheme() ? const TarBarTheme.dark() : const TarBarTheme.light(); | 
					
						
							| 
									
										
										
										
											2022-08-22 13:51:05 +08:00
										 |  |  |     return SubWindowDragToResizeArea( | 
					
						
							|  |  |  |       windowId: windowId(), | 
					
						
							| 
									
										
										
										
											2022-08-22 17:58:48 +08:00
										 |  |  |       child: Container( | 
					
						
							|  |  |  |         decoration: BoxDecoration( | 
					
						
							|  |  |  |             border: Border.all(color: MyTheme.color(context).border!)), | 
					
						
							|  |  |  |         child: Scaffold( | 
					
						
							| 
									
										
										
										
											2022-08-24 21:09:18 +08:00
										 |  |  |             backgroundColor: MyTheme.color(context).bg, | 
					
						
							|  |  |  |             body: DesktopTab( | 
					
						
							|  |  |  |               controller: tabController, | 
					
						
							|  |  |  |               theme: theme, | 
					
						
							| 
									
										
										
										
											2022-08-30 16:50:25 +08:00
										 |  |  |               tabType: DesktopTabType.fileTransfer, | 
					
						
							| 
									
										
										
										
											2022-08-30 20:48:03 +08:00
										 |  |  |               onClose: () { | 
					
						
							| 
									
										
										
										
											2022-08-30 16:50:25 +08:00
										 |  |  |                 tabController.clear(); | 
					
						
							| 
									
										
										
										
											2022-08-30 20:48:03 +08:00
										 |  |  |               }, | 
					
						
							| 
									
										
										
										
											2022-08-24 21:09:18 +08:00
										 |  |  |               tail: AddButton( | 
					
						
							|  |  |  |                 theme: theme, | 
					
						
							|  |  |  |               ).paddingOnly(left: 10), | 
					
						
							|  |  |  |             )), | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void onRemoveId(String id) { | 
					
						
							| 
									
										
										
										
											2022-08-30 16:45:47 +08:00
										 |  |  |     if (tabController.state.value.tabs.isEmpty) { | 
					
						
							|  |  |  |       WindowController.fromWindowId(windowId()).hide(); | 
					
						
							| 
									
										
										
										
											2022-08-09 09:01:06 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-08-09 16:37:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   int windowId() { | 
					
						
							|  |  |  |     return widget.params["windowId"]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-06-17 22:57:41 +08:00
										 |  |  | } |