mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-18 00:21:28 +03:00
@@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -24,22 +23,21 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
with TickerProviderStateMixin {
|
||||
// refactor List<int> when using multi-tab
|
||||
// this singleton is only for test
|
||||
var connectionIds = List<String>.empty(growable: true).obs;
|
||||
var initialIndex = 0;
|
||||
RxList<TabInfo> tabs = List<TabInfo>.empty(growable: true).obs;
|
||||
late Rx<TabController> tabController;
|
||||
static final Rx<int> _selected = 0.obs;
|
||||
IconData icon = Icons.file_copy_sharp;
|
||||
|
||||
_FileManagerTabPageState(Map<String, dynamic> params) {
|
||||
if (params['id'] != null) {
|
||||
connectionIds.add(params['id']);
|
||||
tabs.add(TabInfo(label: params['id'], icon: icon));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
tabController =
|
||||
TabController(length: connectionIds.length, vsync: this).obs;
|
||||
tabController = TabController(length: tabs.length, vsync: this).obs;
|
||||
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
||||
print(
|
||||
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
|
||||
@@ -48,23 +46,13 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
final args = jsonDecode(call.arguments);
|
||||
final id = args['id'];
|
||||
window_on_top(windowId());
|
||||
final indexOf = connectionIds.indexOf(id);
|
||||
if (indexOf >= 0) {
|
||||
initialIndex = indexOf;
|
||||
tabController.value.animateTo(initialIndex, duration: Duration.zero);
|
||||
} else {
|
||||
connectionIds.add(id);
|
||||
initialIndex = connectionIds.length - 1;
|
||||
tabController.value = TabController(
|
||||
length: connectionIds.length,
|
||||
initialIndex: initialIndex,
|
||||
vsync: this);
|
||||
}
|
||||
_selected.value = initialIndex;
|
||||
DesktopTabBar.onAdd(this, tabController, tabs, _selected,
|
||||
TabInfo(label: id, icon: icon));
|
||||
} else if (call.method == "onDestroy") {
|
||||
print("executing onDestroy hook, closing ${connectionIds}");
|
||||
connectionIds.forEach((id) {
|
||||
final tag = 'ft_${id}';
|
||||
print(
|
||||
"executing onDestroy hook, closing ${tabs.map((tab) => tab.label).toList()}");
|
||||
tabs.forEach((tab) {
|
||||
final tag = 'ft_${tab.label}';
|
||||
ffi(tag).close().then((_) {
|
||||
Get.delete<FFI>(tag: tag);
|
||||
});
|
||||
@@ -79,26 +67,22 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Obx(
|
||||
() => DesktopTabBar(
|
||||
controller: tabController,
|
||||
tabs: connectionIds
|
||||
.map((e) => TabInfo(label: e, icon: Icons.file_copy_sharp))
|
||||
.toList(),
|
||||
onTabClose: onRemoveId,
|
||||
selected: _selected,
|
||||
dark: isDarkTheme(),
|
||||
mainTab: false,
|
||||
),
|
||||
DesktopTabBar(
|
||||
controller: tabController,
|
||||
tabs: tabs,
|
||||
onTabClose: onRemoveId,
|
||||
selected: _selected,
|
||||
dark: isDarkTheme(),
|
||||
mainTab: false,
|
||||
),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => TabBarView(
|
||||
controller: tabController.value,
|
||||
children: connectionIds
|
||||
.map((e) => FileManagerPage(
|
||||
key: ValueKey(e),
|
||||
id: e)) //RemotePage(key: ValueKey(e), id: e))
|
||||
children: tabs
|
||||
.map((tab) => FileManagerPage(
|
||||
key: ValueKey(tab.label),
|
||||
id: tab.label)) //RemotePage(key: ValueKey(e), id: e))
|
||||
.toList()),
|
||||
),
|
||||
)
|
||||
@@ -108,15 +92,8 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
|
||||
}
|
||||
|
||||
void onRemoveId(String id) {
|
||||
final indexOf = connectionIds.indexOf(id);
|
||||
if (indexOf == -1) {
|
||||
return;
|
||||
}
|
||||
connectionIds.removeAt(indexOf);
|
||||
initialIndex = max(0, initialIndex - 1);
|
||||
tabController.value = TabController(
|
||||
length: connectionIds.length, initialIndex: initialIndex, vsync: this);
|
||||
if (connectionIds.length == 0) {
|
||||
DesktopTabBar.onClose(this, tabController, tabs, id);
|
||||
if (tabs.length == 0) {
|
||||
WindowController.fromWindowId(windowId()).close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user