mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 19:17:58 +00:00
add: file transfer dual logic with bridge
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/desktop/pages/file_manager_page.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/titlebar_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 {
|
||||
@@ -21,7 +22,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
// refactor List<int> when using multi-tab
|
||||
// this singleton is only for test
|
||||
List<String> connectionIds = List.empty(growable: true);
|
||||
var initialIndex = 0;
|
||||
var initialIndex = 0.obs;
|
||||
|
||||
_FileManagerTabPageState(Map<String, dynamic> params) {
|
||||
if (params['id'] != null) {
|
||||
@@ -37,21 +38,15 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
|
||||
// for simplify, just replace connectionId
|
||||
if (call.method == "new_file_transfer") {
|
||||
setState(() {
|
||||
final args = jsonDecode(call.arguments);
|
||||
final id = args['id'];
|
||||
final indexOf = connectionIds.indexOf(id);
|
||||
if (indexOf >= 0) {
|
||||
setState(() {
|
||||
initialIndex = indexOf;
|
||||
});
|
||||
} else {
|
||||
connectionIds.add(id);
|
||||
setState(() {
|
||||
initialIndex = connectionIds.length - 1;
|
||||
});
|
||||
}
|
||||
});
|
||||
final args = jsonDecode(call.arguments);
|
||||
final id = args['id'];
|
||||
final indexOf = connectionIds.indexOf(id);
|
||||
if (indexOf >= 0) {
|
||||
initialIndex.value = indexOf;
|
||||
} else {
|
||||
connectionIds.add(id);
|
||||
initialIndex.value = connectionIds.length - 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -59,51 +54,53 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: DefaultTabController(
|
||||
initialIndex: initialIndex,
|
||||
length: connectionIds.length,
|
||||
animationDuration: Duration.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
DesktopTitleBar(
|
||||
child: TabBar(
|
||||
isScrollable: true,
|
||||
labelColor: Colors.white,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
indicatorColor: Colors.white,
|
||||
tabs: connectionIds
|
||||
.map((e) => Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(e),
|
||||
SizedBox(
|
||||
width: 4,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
onRemoveId(e);
|
||||
},
|
||||
child: Icon(
|
||||
Icons.highlight_remove,
|
||||
size: 20,
|
||||
))
|
||||
],
|
||||
),
|
||||
))
|
||||
.toList()),
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
children: connectionIds
|
||||
.map((e) => Container(
|
||||
child: FileManagerPage(
|
||||
key: ValueKey(e),
|
||||
id: e))) //RemotePage(key: ValueKey(e), id: e))
|
||||
.toList()),
|
||||
)
|
||||
],
|
||||
body: Obx(
|
||||
()=> DefaultTabController(
|
||||
initialIndex: initialIndex.value,
|
||||
length: connectionIds.length,
|
||||
animationDuration: Duration.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
DesktopTitleBar(
|
||||
child: TabBar(
|
||||
isScrollable: true,
|
||||
labelColor: Colors.white,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
indicatorColor: Colors.white,
|
||||
tabs: connectionIds
|
||||
.map((e) => Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(e),
|
||||
SizedBox(
|
||||
width: 4,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
onRemoveId(e);
|
||||
},
|
||||
child: Icon(
|
||||
Icons.highlight_remove,
|
||||
size: 20,
|
||||
))
|
||||
],
|
||||
),
|
||||
))
|
||||
.toList()),
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
children: connectionIds
|
||||
.map((e) => Container(
|
||||
child: FileManagerPage(
|
||||
key: ValueKey(e),
|
||||
id: e))) //RemotePage(key: ValueKey(e), id: e))
|
||||
.toList()),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -114,9 +111,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
if (indexOf == -1) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
connectionIds.removeAt(indexOf);
|
||||
initialIndex = max(0, initialIndex - 1);
|
||||
});
|
||||
connectionIds.removeAt(indexOf);
|
||||
initialIndex.value = max(0, initialIndex.value - 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user