Skip to content

Commit

Permalink
Merge pull request rustdesk#5821 from 21pages/tab_label
Browse files Browse the repository at this point in the history
desktop tab lable format: id/alias@hostname
  • Loading branch information
rustdesk authored Sep 26, 2023
2 parents 4e97d25 + e000fdf commit d9ee9ba
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
20 changes: 19 additions & 1 deletion flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ String getWindowName({WindowType? overrideType}) {
}

String getWindowNameWithId(String id, {WindowType? overrideType}) {
return "${DesktopTab.labelGetterAlias(id).value} - ${getWindowName(overrideType: overrideType)}";
return "${DesktopTab.tablabelGetter(id).value} - ${getWindowName(overrideType: overrideType)}";
}

Future<void> updateSystemWindowTheme() async {
Expand Down Expand Up @@ -2536,3 +2536,21 @@ Widget buildErrorBanner(BuildContext context,
)).marginOnly(bottom: 14),
));
}

String getDesktopTabLabel(String peerId, String alias) {
String label = alias.isEmpty ? peerId : alias;
try {
String peer = bind.mainGetPeerSync(id: peerId);
Map<String, dynamic> config = jsonDecode(peer);
if (config['info']['hostname'] is String) {
String hostname = config['info']['hostname'];
if (hostname.isNotEmpty &&
!label.toLowerCase().contains(hostname.toLowerCase())) {
label += "@$hostname";
}
}
} catch (e) {
debugPrint("Failed to get hostname:$e");
}
return label;
}
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/file_manager_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
controller: tabController,
onWindowCloseButton: handleWindowCloseButton,
tail: const AddButton().paddingOnly(left: 10),
labelGetter: DesktopTab.labelGetterAlias,
labelGetter: DesktopTab.tablabelGetter,
)),
);
return Platform.isMacOS || kUseCompatibleUiMode
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/port_forward_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class _PortForwardPageState extends State<PortForwardPage>
}

void refreshTunnelConfig() async {
String peer = await bind.mainGetPeer(id: widget.id);
String peer = bind.mainGetPeerSync(id: widget.id);
Map<String, dynamic> config = jsonDecode(peer);
List<dynamic> infos = config['port_forwards'] as List;
List<_PortForward> result = List.empty(growable: true);
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/port_forward_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
return true;
},
tail: AddButton().paddingOnly(left: 10),
labelGetter: DesktopTab.labelGetterAlias,
labelGetter: DesktopTab.tablabelGetter,
)),
);
return Platform.isMacOS || kUseCompatibleUiMode
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/remote_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
onWindowCloseButton: handleWindowCloseButton,
tail: const AddButton().paddingOnly(left: 10),
pageViewBuilder: (pageView) => pageView,
labelGetter: DesktopTab.labelGetterAlias,
labelGetter: DesktopTab.tablabelGetter,
tabBuilder: (key, icon, label, themeConf) => Obx(() {
final connectionType = ConnectionTypeState.find(key);
if (!connectionType.isValid()) {
Expand Down
31 changes: 17 additions & 14 deletions flutter/lib/desktop/widgets/tabbar_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'dart:ui' as ui;
Expand Down Expand Up @@ -267,13 +268,12 @@ class DesktopTab extends StatelessWidget {
tabType == DesktopTabType.install;
}

static RxString labelGetterAlias(String peerId) {
final opt = 'alias';
PeerStringOption.init(peerId, opt, () {
final alias = bind.mainGetPeerOptionSync(id: peerId, key: opt);
return alias.isEmpty ? peerId : alias;
static RxString tablabelGetter(String peerId) {
PeerStringOption.init(peerId, 'tabLabel', () {
final alias = bind.mainGetPeerOptionSync(id: peerId, key: 'alias');
return getDesktopTabLabel(peerId, alias);
});
return PeerStringOption.find(peerId, opt);
return PeerStringOption.find(peerId, 'tabLabel');
}

@override
Expand Down Expand Up @@ -921,14 +921,17 @@ class _TabState extends State<_Tab> with RestorationMixin {
final labelWidget = Obx(() {
return ConstrainedBox(
constraints: BoxConstraints(maxWidth: widget.maxLabelWidth ?? 200),
child: Text(
translate(widget.label.value),
textAlign: TextAlign.center,
style: TextStyle(
color: isSelected
? MyTheme.tabbar(context).selectedTextColor
: MyTheme.tabbar(context).unSelectedTextColor),
overflow: TextOverflow.ellipsis,
child: Tooltip(
message: translate(widget.label.value),
child: Text(
translate(widget.label.value),
textAlign: TextAlign.center,
style: TextStyle(
color: isSelected
? MyTheme.tabbar(context).selectedTextColor
: MyTheme.tabbar(context).unSelectedTextColor),
overflow: TextOverflow.ellipsis,
),
));
});

Expand Down
11 changes: 8 additions & 3 deletions flutter/lib/models/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
import 'package:flutter_hbb/generated_bridge.dart';
import 'package:flutter_hbb/models/ab_model.dart';
import 'package:flutter_hbb/models/chat_model.dart';
Expand Down Expand Up @@ -353,9 +354,13 @@ class FfiModel with ChangeNotifier {
}

handleAliasChanged(Map<String, dynamic> evt) {
final rxAlias = PeerStringOption.find(evt['id'], 'alias');
if (rxAlias.value != evt['alias']) {
rxAlias.value = evt['alias'];
if (!isDesktop) return;
final String peerId = evt['id'];
final String alias = evt['alias'];
String label = getDesktopTabLabel(peerId, alias);
final rxTabLabel = PeerStringOption.find(evt['id'], 'tabLabel');
if (rxTabLabel.value != label) {
rxTabLabel.value = label;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/flutter_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,9 @@ pub fn main_store_fav(favs: Vec<String>) {
store_fav(favs)
}

pub fn main_get_peer(id: String) -> String {
pub fn main_get_peer_sync(id: String) -> SyncReturn<String> {
let conf = get_peer(id);
serde_json::to_string(&conf).unwrap_or("".to_string())
SyncReturn(serde_json::to_string(&conf).unwrap_or("".to_string()))
}

pub fn main_get_lan_peers() -> String {
Expand Down

0 comments on commit d9ee9ba

Please sign in to comment.