Hide MAC and show hostname when IP address is available

This commit is contained in:
Marc Brooks 2025-10-27 18:01:55 -05:00
parent 0d7cfec3e9
commit 1138ffc210
No known key found for this signature in database
GPG Key ID: 583A6AF2D6AE1DC6
4 changed files with 26 additions and 14 deletions

View File

@ -41,10 +41,15 @@ func switchToMainScreen() {
func updateDisplay() {
if networkManager != nil {
nativeInstance.UpdateLabelIfChanged("home_info_ipv4_addr", networkManager.IPv4String())
nativeInstance.UpdateLabelAndChangeVisibility("home_info_ipv4_addr", networkManager.IPv4String())
nativeInstance.UpdateLabelAndChangeVisibility("home_info_ipv6_addr", networkManager.IPv6String())
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkManager.MACString())
nativeInstance.UpdateLabelIfChanged("home_info_hostname", networkManager.Hostname())
// we either show the MAC address (if no IP yet) or the hostname (if either IPv4 or IPv6 are available)
hasIP := networkManager.IPv4Ready() || networkManager.IPv6Ready()
nativeInstance.ChangeVisibility("home_info_mac_addr", !hasIP)
nativeInstance.ChangeVisibility("home_info_hostname", hasIP)
}
_, _ = nativeInstance.UIObjHide("menu_btn_network")
@ -71,6 +76,7 @@ func updateDisplay() {
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
_, _ = nativeInstance.UIObjClearState("hdmi_status_label", "LV_STATE_CHECKED")
}
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
if networkManager != nil && networkManager.IsUp() {

View File

@ -117,14 +117,18 @@ func (n *Native) UpdateLabelIfChanged(objName string, newText string) {
// UpdateLabelAndChangeVisibility updates the label and changes the visibility of the object
func (n *Native) UpdateLabelAndChangeVisibility(objName string, newText string) {
n.UpdateLabelIfChanged(objName, newText)
n.ChangeVisibility(objName, newText != "")
}
// ChangeVisibility shows or hides an object AND the container it is in
func (n *Native) ChangeVisibility(objName string, show bool) {
containerName := objName + "_container"
if newText == "" {
_, _ = n.UIObjHide(objName)
_, _ = n.UIObjHide(containerName)
} else {
if show {
_, _ = n.UIObjShow(objName)
_, _ = n.UIObjShow(containerName)
} else {
_, _ = n.UIObjHide(objName)
_, _ = n.UIObjHide(containerName)
}
}

View File

@ -1227,8 +1227,8 @@
"type": "LVGLLabelWidget",
"left": 0,
"top": 0,
"width": 174,
"height": 25,
"width": 217,
"height": 31,
"customInputs": [],
"customOutputs": [],
"style": {
@ -1251,7 +1251,7 @@
"checkedStateType": "literal",
"disabledStateType": "literal",
"states": "",
"useStyle": "LabelFontBold24",
"useStyle": "LabelFontBold30",
"localStyles": {
"objID": "e584be1c-d434-4f13-fb87-00665e4a53a9"
},
@ -1287,7 +1287,7 @@
"heightUnit": "content",
"children": [],
"widgetFlags": "CLICK_FOCUSABLE|GESTURE_BUBBLE|PRESS_LOCK|SCROLLABLE|SCROLL_CHAIN_HOR|SCROLL_CHAIN_VER|SCROLL_ELASTIC|SCROLL_MOMENTUM|SCROLL_WITH_ARROW|SNAPPABLE",
"hiddenFlag": true,
"hiddenFlag": false,
"hiddenFlagType": "literal",
"clickableFlagType": "literal",
"checkedStateType": "literal",
@ -1335,6 +1335,7 @@
"heightUnit": "content",
"children": [],
"widgetFlags": "CLICK_FOCUSABLE|GESTURE_BUBBLE|PRESS_LOCK|SCROLLABLE|SCROLL_CHAIN_HOR|SCROLL_CHAIN_VER|SCROLL_ELASTIC|SCROLL_MOMENTUM|SCROLL_WITH_ARROW|SNAPPABLE",
"hiddenFlag": false,
"hiddenFlagType": "literal",
"clickableFlagType": "literal",
"checkedStateType": "literal",
@ -1362,8 +1363,8 @@
"type": "LVGLLabelWidget",
"left": 0,
"top": 0,
"width": 60,
"height": 18,
"width": 74,
"height": 21,
"customInputs": [],
"customOutputs": [],
"style": {
@ -1393,7 +1394,8 @@
"MAIN": {
"DEFAULT": {
"pad_bottom": 2,
"pad_top": -1
"pad_top": -1,
"text_font": "FontBook20"
}
}
}

View File

@ -318,7 +318,7 @@ void create_screen_home_screen() {
objects.home_info_ipv4_addr = obj;
lv_obj_set_pos(obj, LV_PCT(0), LV_PCT(0));
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
add_style_label_font_bold24(obj);
add_style_label_font_bold30(obj);
lv_label_set_text(obj, "169.254.169.254");
}
{
@ -328,7 +328,6 @@ void create_screen_home_screen() {
lv_obj_set_pos(obj, LV_PCT(0), LV_PCT(0));
lv_obj_set_size(obj, LV_PCT(100), LV_SIZE_CONTENT);
lv_label_set_long_mode(obj, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
add_style_label_font16(obj);
lv_obj_set_style_text_font(obj, &ui_font_font_book16, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_top(obj, -1, LV_PART_MAIN | LV_STATE_DEFAULT);
@ -354,6 +353,7 @@ void create_screen_home_screen() {
add_style_label_font16(obj);
lv_obj_set_style_pad_bottom(obj, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_top(obj, -1, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(obj, &ui_font_font_book20, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(obj, "JetKVM");
}
}