mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-11 18:47:47 +00:00
@@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -36,7 +37,10 @@ class PeerTabModel with ChangeNotifier {
|
||||
IconFont.addressBook,
|
||||
Icons.group,
|
||||
];
|
||||
final List<bool> _isVisible = List.filled(4, true, growable: false);
|
||||
List<bool> get isVisible => _isVisible;
|
||||
List<int> get indexs => List.generate(tabNames.length, (index) => index);
|
||||
List<int> get visibleIndexs => indexs.where((e) => _isVisible[e]).toList();
|
||||
List<Peer> _selectedPeers = List.empty(growable: true);
|
||||
List<Peer> get selectedPeers => _selectedPeers;
|
||||
bool _multiSelectionMode = false;
|
||||
@@ -49,12 +53,29 @@ class PeerTabModel with ChangeNotifier {
|
||||
String get lastId => _lastId;
|
||||
|
||||
PeerTabModel(this.parent) {
|
||||
// visible
|
||||
try {
|
||||
final option = bind.getLocalFlutterOption(k: 'peer-tab-visible');
|
||||
if (option.isNotEmpty) {
|
||||
List<dynamic> decodeList = jsonDecode(option);
|
||||
if (decodeList.length == _isVisible.length) {
|
||||
for (int i = 0; i < _isVisible.length; i++) {
|
||||
if (decodeList[i] is bool) {
|
||||
_isVisible[i] = decodeList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("failed to get peer tab visible list:$e");
|
||||
}
|
||||
// init currentTab
|
||||
_currentTab =
|
||||
int.tryParse(bind.getLocalFlutterOption(k: 'peer-tab-index')) ?? 0;
|
||||
if (_currentTab < 0 || _currentTab >= tabNames.length) {
|
||||
_currentTab = 0;
|
||||
}
|
||||
_trySetCurrentTabToFirstVisible();
|
||||
}
|
||||
|
||||
setCurrentTab(int index) {
|
||||
@@ -158,4 +179,31 @@ class PeerTabModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTabVisible(int index, bool visible) {
|
||||
if (index >= 0 && index < _isVisible.length) {
|
||||
if (_isVisible[index] != visible) {
|
||||
_isVisible[index] = visible;
|
||||
if (index == _currentTab && !visible) {
|
||||
_trySetCurrentTabToFirstVisible();
|
||||
} else if (visible && visibleIndexs.length == 1) {
|
||||
_currentTab = index;
|
||||
}
|
||||
try {
|
||||
bind.setLocalFlutterOption(
|
||||
k: 'peer-tab-visible', v: jsonEncode(_isVisible));
|
||||
} catch (_) {}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_trySetCurrentTabToFirstVisible() {
|
||||
if (!_isVisible[_currentTab]) {
|
||||
int firstVisible = _isVisible.indexWhere((e) => e);
|
||||
if (firstVisible >= 0) {
|
||||
_currentTab = firstVisible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user