desktop tab lable format: id/alias@hostname
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
4e97d2503b
commit
e000fdfb50
@ -2303,7 +2303,7 @@ String getWindowName({WindowType? overrideType}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getWindowNameWithId(String id, {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 {
|
Future<void> updateSystemWindowTheme() async {
|
||||||
@ -2536,3 +2536,21 @@ Widget buildErrorBanner(BuildContext context,
|
|||||||
)).marginOnly(bottom: 14),
|
)).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,
|
controller: tabController,
|
||||||
onWindowCloseButton: handleWindowCloseButton,
|
onWindowCloseButton: handleWindowCloseButton,
|
||||||
tail: const AddButton().paddingOnly(left: 10),
|
tail: const AddButton().paddingOnly(left: 10),
|
||||||
labelGetter: DesktopTab.labelGetterAlias,
|
labelGetter: DesktopTab.tablabelGetter,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
return Platform.isMacOS || kUseCompatibleUiMode
|
return Platform.isMacOS || kUseCompatibleUiMode
|
||||||
|
@ -266,7 +266,7 @@ class _PortForwardPageState extends State<PortForwardPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void refreshTunnelConfig() async {
|
void refreshTunnelConfig() async {
|
||||||
String peer = await bind.mainGetPeer(id: widget.id);
|
String peer = bind.mainGetPeerSync(id: widget.id);
|
||||||
Map<String, dynamic> config = jsonDecode(peer);
|
Map<String, dynamic> config = jsonDecode(peer);
|
||||||
List<dynamic> infos = config['port_forwards'] as List;
|
List<dynamic> infos = config['port_forwards'] as List;
|
||||||
List<_PortForward> result = List.empty(growable: true);
|
List<_PortForward> result = List.empty(growable: true);
|
||||||
|
@ -108,7 +108,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
tail: AddButton().paddingOnly(left: 10),
|
tail: AddButton().paddingOnly(left: 10),
|
||||||
labelGetter: DesktopTab.labelGetterAlias,
|
labelGetter: DesktopTab.tablabelGetter,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
return Platform.isMacOS || kUseCompatibleUiMode
|
return Platform.isMacOS || kUseCompatibleUiMode
|
||||||
|
@ -210,7 +210,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
onWindowCloseButton: handleWindowCloseButton,
|
onWindowCloseButton: handleWindowCloseButton,
|
||||||
tail: const AddButton().paddingOnly(left: 10),
|
tail: const AddButton().paddingOnly(left: 10),
|
||||||
pageViewBuilder: (pageView) => pageView,
|
pageViewBuilder: (pageView) => pageView,
|
||||||
labelGetter: DesktopTab.labelGetterAlias,
|
labelGetter: DesktopTab.tablabelGetter,
|
||||||
tabBuilder: (key, icon, label, themeConf) => Obx(() {
|
tabBuilder: (key, icon, label, themeConf) => Obx(() {
|
||||||
final connectionType = ConnectionTypeState.find(key);
|
final connectionType = ConnectionTypeState.find(key);
|
||||||
if (!connectionType.isValid()) {
|
if (!connectionType.isValid()) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
@ -267,13 +268,12 @@ class DesktopTab extends StatelessWidget {
|
|||||||
tabType == DesktopTabType.install;
|
tabType == DesktopTabType.install;
|
||||||
}
|
}
|
||||||
|
|
||||||
static RxString labelGetterAlias(String peerId) {
|
static RxString tablabelGetter(String peerId) {
|
||||||
final opt = 'alias';
|
PeerStringOption.init(peerId, 'tabLabel', () {
|
||||||
PeerStringOption.init(peerId, opt, () {
|
final alias = bind.mainGetPeerOptionSync(id: peerId, key: 'alias');
|
||||||
final alias = bind.mainGetPeerOptionSync(id: peerId, key: opt);
|
return getDesktopTabLabel(peerId, alias);
|
||||||
return alias.isEmpty ? peerId : alias;
|
|
||||||
});
|
});
|
||||||
return PeerStringOption.find(peerId, opt);
|
return PeerStringOption.find(peerId, 'tabLabel');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -921,14 +921,17 @@ class _TabState extends State<_Tab> with RestorationMixin {
|
|||||||
final labelWidget = Obx(() {
|
final labelWidget = Obx(() {
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: BoxConstraints(maxWidth: widget.maxLabelWidth ?? 200),
|
constraints: BoxConstraints(maxWidth: widget.maxLabelWidth ?? 200),
|
||||||
child: Text(
|
child: Tooltip(
|
||||||
translate(widget.label.value),
|
message: translate(widget.label.value),
|
||||||
textAlign: TextAlign.center,
|
child: Text(
|
||||||
style: TextStyle(
|
translate(widget.label.value),
|
||||||
color: isSelected
|
textAlign: TextAlign.center,
|
||||||
? MyTheme.tabbar(context).selectedTextColor
|
style: TextStyle(
|
||||||
: MyTheme.tabbar(context).unSelectedTextColor),
|
color: isSelected
|
||||||
overflow: TextOverflow.ellipsis,
|
? 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/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hbb/consts.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/generated_bridge.dart';
|
||||||
import 'package:flutter_hbb/models/ab_model.dart';
|
import 'package:flutter_hbb/models/ab_model.dart';
|
||||||
import 'package:flutter_hbb/models/chat_model.dart';
|
import 'package:flutter_hbb/models/chat_model.dart';
|
||||||
@ -353,9 +354,13 @@ class FfiModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleAliasChanged(Map<String, dynamic> evt) {
|
handleAliasChanged(Map<String, dynamic> evt) {
|
||||||
final rxAlias = PeerStringOption.find(evt['id'], 'alias');
|
if (!isDesktop) return;
|
||||||
if (rxAlias.value != evt['alias']) {
|
final String peerId = evt['id'];
|
||||||
rxAlias.value = evt['alias'];
|
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)
|
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);
|
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 {
|
pub fn main_get_lan_peers() -> String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user