Merge pull request #5821 from 21pages/tab_label
desktop tab lable format: id/alias@hostname
This commit is contained in:
		
						commit
						d9ee9ba238
					
				| @ -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 { | ||||
| @ -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; | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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()) { | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| import 'dart:async'; | ||||
| import 'dart:convert'; | ||||
| import 'dart:io'; | ||||
| import 'dart:math'; | ||||
| import 'dart:ui' as ui; | ||||
| @ -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 | ||||
| @ -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, | ||||
|             ), | ||||
|           )); | ||||
|     }); | ||||
| 
 | ||||
|  | ||||
| @ -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'; | ||||
| @ -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; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -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 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user