refactor DesktopTab impl for cm
This commit is contained in:
parent
67b40b2cc7
commit
e78d44935a
@ -79,6 +79,8 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
gFFI.serverModel.updateClientState();
|
gFFI.serverModel.updateClientState();
|
||||||
|
gFFI.serverModel.tabController.onSelected = (index) =>
|
||||||
|
gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id);
|
||||||
// test
|
// test
|
||||||
// gFFI.serverModel.clients.forEach((client) {
|
// gFFI.serverModel.clients.forEach((client) {
|
||||||
// DesktopTabBar.onAdd(
|
// DesktopTabBar.onAdd(
|
||||||
@ -103,38 +105,20 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: Column(
|
: DesktopTab(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
theme: isDarkTheme() ? TarBarTheme.dark() : TarBarTheme.light(),
|
||||||
children: [
|
showTitle: false,
|
||||||
SizedBox(
|
showMaximize: false,
|
||||||
height: kTextTabBarHeight,
|
showMinimize: false,
|
||||||
child: Obx(() => DesktopTabBar(
|
controller: serverModel.tabController,
|
||||||
dark: isDarkTheme(),
|
isMainWindow: true,
|
||||||
mainTab: true,
|
pageViewBuilder: (pageView) => Row(children: [
|
||||||
tabs: serverModel.tabs,
|
Expanded(child: pageView),
|
||||||
showTitle: false,
|
|
||||||
showMaximize: false,
|
|
||||||
showMinimize: false,
|
|
||||||
onSelected: (index) => gFFI.chatModel
|
|
||||||
.changeCurrentID(serverModel.clients[index].id),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Row(children: [
|
|
||||||
Expanded(
|
|
||||||
child: PageView(
|
|
||||||
controller: DesktopTabBar.controller.value,
|
|
||||||
children: serverModel.clients
|
|
||||||
.map((client) => buildConnectionCard(client))
|
|
||||||
.toList(growable: false))),
|
|
||||||
Consumer<ChatModel>(
|
Consumer<ChatModel>(
|
||||||
builder: (_, model, child) => model.isShowChatPage
|
builder: (_, model, child) => model.isShowChatPage
|
||||||
? Expanded(child: Scaffold(body: ChatPage()))
|
? Expanded(child: Scaffold(body: ChatPage()))
|
||||||
: Offstage())
|
: Offstage())
|
||||||
]),
|
]));
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildTitleBar(Widget middle) {
|
Widget buildTitleBar(Widget middle) {
|
||||||
@ -156,23 +140,6 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildConnectionCard(Client client) {
|
|
||||||
return Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
key: ValueKey(client.id),
|
|
||||||
children: [
|
|
||||||
_CmHeader(client: client),
|
|
||||||
client.isFileTransfer ? Offstage() : _PrivilegeBoard(client: client),
|
|
||||||
Expanded(
|
|
||||||
child: Align(
|
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: _CmControlPanel(client: client),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
).paddingSymmetric(vertical: 8.0, horizontal: 8.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildTab(Client client) {
|
Widget buildTab(Client client) {
|
||||||
return Tab(
|
return Tab(
|
||||||
child: Row(
|
child: Row(
|
||||||
@ -191,6 +158,23 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget buildConnectionCard(Client client) {
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
key: ValueKey(client.id),
|
||||||
|
children: [
|
||||||
|
_CmHeader(client: client),
|
||||||
|
client.isFileTransfer ? Offstage() : _PrivilegeBoard(client: client),
|
||||||
|
Expanded(
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: _CmControlPanel(client: client),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
).paddingSymmetric(vertical: 8.0, horizontal: 8.0);
|
||||||
|
}
|
||||||
|
|
||||||
class _AppIcon extends StatelessWidget {
|
class _AppIcon extends StatelessWidget {
|
||||||
const _AppIcon({Key? key}) : super(key: key);
|
const _AppIcon({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@ -421,9 +405,11 @@ class _CmControlPanel extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return client.authorized
|
return Consumer<ServerModel>(builder: (_, model, child) {
|
||||||
? buildAuthorized(context)
|
return client.authorized
|
||||||
: buildUnAuthorized(context);
|
? buildAuthorized(context)
|
||||||
|
: buildUnAuthorized(context);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
buildAuthorized(BuildContext context) {
|
buildAuthorized(BuildContext context) {
|
||||||
|
@ -51,6 +51,8 @@ class DesktopTabController {
|
|||||||
/// index, key
|
/// index, key
|
||||||
Function(int, String)? onRemove;
|
Function(int, String)? onRemove;
|
||||||
|
|
||||||
|
Function(int)? onSelected;
|
||||||
|
|
||||||
void add(TabInfo tab) {
|
void add(TabInfo tab) {
|
||||||
if (!isDesktop) return;
|
if (!isDesktop) return;
|
||||||
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
||||||
@ -96,8 +98,7 @@ class DesktopTabController {
|
|||||||
val.pageController.jumpToPage(index);
|
val.pageController.jumpToPage(index);
|
||||||
val.scrollController.scrollToItem(index, center: true, animate: true);
|
val.scrollController.scrollToItem(index, center: true, animate: true);
|
||||||
});
|
});
|
||||||
|
onSelected?.call(index);
|
||||||
// onSelected callback
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeBy(String? key) {
|
void closeBy(String? key) {
|
||||||
@ -172,7 +173,6 @@ class DesktopTab extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPageView() {
|
Widget _buildPageView() {
|
||||||
debugPrint("_buildPageView: ${state.value.tabs.length}");
|
|
||||||
return Obx(() => PageView(
|
return Obx(() => PageView(
|
||||||
controller: state.value.pageController,
|
controller: state.value.pageController,
|
||||||
children:
|
children:
|
||||||
|
@ -200,6 +200,7 @@ class ChatModel with ChangeNotifier {
|
|||||||
if (!_isShowChatPage) {
|
if (!_isShowChatPage) {
|
||||||
toggleCMChatPage(id);
|
toggleCMChatPage(id);
|
||||||
}
|
}
|
||||||
|
_ffi.target?.serverModel.jumpTo(id);
|
||||||
|
|
||||||
late final chatUser;
|
late final chatUser;
|
||||||
if (id == clientModeID) {
|
if (id == clientModeID) {
|
||||||
|
@ -4,10 +4,10 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/models/platform_model.dart';
|
import 'package:flutter_hbb/models/platform_model.dart';
|
||||||
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
|
||||||
import 'package:wakelock/wakelock.dart';
|
import 'package:wakelock/wakelock.dart';
|
||||||
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
|
import '../desktop/pages/server_page.dart' as Desktop;
|
||||||
import '../desktop/widgets/tabbar_widget.dart';
|
import '../desktop/widgets/tabbar_widget.dart';
|
||||||
import '../mobile/pages/server_page.dart';
|
import '../mobile/pages/server_page.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
@ -32,7 +32,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
late final TextEditingController _serverId;
|
late final TextEditingController _serverId;
|
||||||
final _serverPasswd = TextEditingController(text: "");
|
final _serverPasswd = TextEditingController(text: "");
|
||||||
|
|
||||||
RxList<TabInfo> tabs = RxList<TabInfo>.empty(growable: true);
|
final tabController = DesktopTabController();
|
||||||
|
|
||||||
List<Client> _clients = [];
|
List<Client> _clients = [];
|
||||||
|
|
||||||
@ -352,16 +352,15 @@ class ServerModel with ChangeNotifier {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
_clients.clear();
|
_clients.clear();
|
||||||
tabs.clear();
|
tabController.state.value.tabs.clear();
|
||||||
for (var clientJson in clientsJson) {
|
for (var clientJson in clientsJson) {
|
||||||
final client = Client.fromJson(clientJson);
|
final client = Client.fromJson(clientJson);
|
||||||
_clients.add(client);
|
_clients.add(client);
|
||||||
DesktopTabBar.onAdd(
|
tabController.add(TabInfo(
|
||||||
tabs,
|
key: client.id.toString(),
|
||||||
TabInfo(
|
label: client.name,
|
||||||
key: client.id.toString(),
|
closable: false,
|
||||||
label: client.name,
|
page: Desktop.buildConnectionCard(client)));
|
||||||
closable: false));
|
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -376,10 +375,11 @@ class ServerModel with ChangeNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_clients.add(client);
|
_clients.add(client);
|
||||||
DesktopTabBar.onAdd(
|
tabController.add(TabInfo(
|
||||||
tabs,
|
key: client.id.toString(),
|
||||||
TabInfo(
|
label: client.name,
|
||||||
key: client.id.toString(), label: client.name, closable: false));
|
closable: false,
|
||||||
|
page: Desktop.buildConnectionCard(client)));
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
if (isAndroid) showLoginDialog(client);
|
if (isAndroid) showLoginDialog(client);
|
||||||
@ -456,7 +456,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
bind.cmLoginRes(connId: client.id, res: res);
|
bind.cmLoginRes(connId: client.id, res: res);
|
||||||
parent.target?.invokeMethod("cancel_notification", client.id);
|
parent.target?.invokeMethod("cancel_notification", client.id);
|
||||||
final index = _clients.indexOf(client);
|
final index = _clients.indexOf(client);
|
||||||
DesktopTabBar.remove(tabs, index);
|
tabController.remove(index);
|
||||||
_clients.remove(client);
|
_clients.remove(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -471,10 +471,11 @@ class ServerModel with ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
_clients[index].authorized = true;
|
_clients[index].authorized = true;
|
||||||
}
|
}
|
||||||
DesktopTabBar.onAdd(
|
tabController.add(TabInfo(
|
||||||
tabs,
|
key: client.id.toString(),
|
||||||
TabInfo(
|
label: client.name,
|
||||||
key: client.id.toString(), label: client.name, closable: false));
|
closable: false,
|
||||||
|
page: Desktop.buildConnectionCard(client)));
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@ -486,7 +487,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
if (_clients.any((c) => c.id == id)) {
|
if (_clients.any((c) => c.id == id)) {
|
||||||
final index = _clients.indexWhere((client) => client.id == id);
|
final index = _clients.indexWhere((client) => client.id == id);
|
||||||
_clients.removeAt(index);
|
_clients.removeAt(index);
|
||||||
DesktopTabBar.remove(tabs, index);
|
tabController.remove(index);
|
||||||
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
|
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
|
||||||
parent.target?.invokeMethod("cancel_notification", id);
|
parent.target?.invokeMethod("cancel_notification", id);
|
||||||
}
|
}
|
||||||
@ -501,7 +502,12 @@ class ServerModel with ChangeNotifier {
|
|||||||
bind.cmCloseConnection(connId: client.id);
|
bind.cmCloseConnection(connId: client.id);
|
||||||
});
|
});
|
||||||
_clients.clear();
|
_clients.clear();
|
||||||
tabs.clear();
|
tabController.state.value.tabs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jumpTo(int id) {
|
||||||
|
final index = _clients.indexWhere((client) => client.id == id);
|
||||||
|
tabController.jumpTo(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user