mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
refactor DesktopTab impl for cm
This commit is contained in:
@@ -79,6 +79,8 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
||||
@override
|
||||
void initState() {
|
||||
gFFI.serverModel.updateClientState();
|
||||
gFFI.serverModel.tabController.onSelected = (index) =>
|
||||
gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id);
|
||||
// test
|
||||
// gFFI.serverModel.clients.forEach((client) {
|
||||
// DesktopTabBar.onAdd(
|
||||
@@ -103,38 +105,20 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: kTextTabBarHeight,
|
||||
child: Obx(() => DesktopTabBar(
|
||||
dark: isDarkTheme(),
|
||||
mainTab: true,
|
||||
tabs: serverModel.tabs,
|
||||
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))),
|
||||
: DesktopTab(
|
||||
theme: isDarkTheme() ? TarBarTheme.dark() : TarBarTheme.light(),
|
||||
showTitle: false,
|
||||
showMaximize: false,
|
||||
showMinimize: false,
|
||||
controller: serverModel.tabController,
|
||||
isMainWindow: true,
|
||||
pageViewBuilder: (pageView) => Row(children: [
|
||||
Expanded(child: pageView),
|
||||
Consumer<ChatModel>(
|
||||
builder: (_, model, child) => model.isShowChatPage
|
||||
? Expanded(child: Scaffold(body: ChatPage()))
|
||||
: Offstage())
|
||||
]),
|
||||
)
|
||||
],
|
||||
);
|
||||
]));
|
||||
}
|
||||
|
||||
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) {
|
||||
return Tab(
|
||||
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 {
|
||||
const _AppIcon({Key? key}) : super(key: key);
|
||||
|
||||
@@ -421,9 +405,11 @@ class _CmControlPanel extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return client.authorized
|
||||
? buildAuthorized(context)
|
||||
: buildUnAuthorized(context);
|
||||
return Consumer<ServerModel>(builder: (_, model, child) {
|
||||
return client.authorized
|
||||
? buildAuthorized(context)
|
||||
: buildUnAuthorized(context);
|
||||
});
|
||||
}
|
||||
|
||||
buildAuthorized(BuildContext context) {
|
||||
|
||||
@@ -51,6 +51,8 @@ class DesktopTabController {
|
||||
/// index, key
|
||||
Function(int, String)? onRemove;
|
||||
|
||||
Function(int)? onSelected;
|
||||
|
||||
void add(TabInfo tab) {
|
||||
if (!isDesktop) return;
|
||||
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
||||
@@ -96,8 +98,7 @@ class DesktopTabController {
|
||||
val.pageController.jumpToPage(index);
|
||||
val.scrollController.scrollToItem(index, center: true, animate: true);
|
||||
});
|
||||
|
||||
// onSelected callback
|
||||
onSelected?.call(index);
|
||||
}
|
||||
|
||||
void closeBy(String? key) {
|
||||
@@ -172,7 +173,6 @@ class DesktopTab extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildPageView() {
|
||||
debugPrint("_buildPageView: ${state.value.tabs.length}");
|
||||
return Obx(() => PageView(
|
||||
controller: state.value.pageController,
|
||||
children:
|
||||
|
||||
Reference in New Issue
Block a user