mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-29 16:34:21 +08:00
66a2c51ca5
Signed-off-by: Kingtous <kingtous@qq.com>
95 lines
2.9 KiB
Dart
95 lines
2.9 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hbb/common.dart';
|
|
import 'package:flutter_hbb/desktop/pages/file_manager_page.dart';
|
|
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
|
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
/// 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);
|
|
}
|
|
|
|
class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
|
final tabController = Get.put(DesktopTabController());
|
|
|
|
static final IconData selectedIcon = Icons.file_copy_sharp;
|
|
static final IconData unselectedIcon = Icons.file_copy_outlined;
|
|
|
|
_FileManagerTabPageState(Map<String, dynamic> params) {
|
|
tabController.add(TabInfo(
|
|
key: params['id'],
|
|
label: params['id'],
|
|
selectedIcon: selectedIcon,
|
|
unselectedIcon: unselectedIcon,
|
|
page: FileManagerPage(key: ValueKey(params['id']), id: params['id'])));
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
tabController.onRemove = (_, id) => onRemoveId(id);
|
|
|
|
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
|
print(
|
|
"call ${call.method} with args ${call.arguments} from window ${fromWindowId} to ${windowId()}");
|
|
// for simplify, just replace connectionId
|
|
if (call.method == "new_file_transfer") {
|
|
final args = jsonDecode(call.arguments);
|
|
final id = args['id'];
|
|
window_on_top(windowId());
|
|
tabController.add(TabInfo(
|
|
key: id,
|
|
label: id,
|
|
selectedIcon: selectedIcon,
|
|
unselectedIcon: unselectedIcon,
|
|
page: FileManagerPage(key: ValueKey(id), id: id)));
|
|
} else if (call.method == "onDestroy") {
|
|
tabController.state.value.tabs.clear();
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme =
|
|
isDarkTheme() ? const TarBarTheme.dark() : const TarBarTheme.light();
|
|
return SubWindowDragToResizeArea(
|
|
windowId: windowId(),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: MyTheme.color(context).border!)),
|
|
child: Scaffold(
|
|
backgroundColor: MyTheme.color(context).bg,
|
|
body: DesktopTab(
|
|
controller: tabController,
|
|
theme: theme,
|
|
isMainWindow: false,
|
|
tail: AddButton(
|
|
theme: theme,
|
|
).paddingOnly(left: 10),
|
|
)),
|
|
),
|
|
);
|
|
}
|
|
|
|
void onRemoveId(String id) {
|
|
if (tabController.state.value.tabs.isEmpty) {
|
|
WindowController.fromWindowId(windowId()).hide();
|
|
}
|
|
}
|
|
|
|
int windowId() {
|
|
return widget.params["windowId"];
|
|
}
|
|
}
|