Skip to content

Commit 6ee63d9

Browse files
osupdate: only show update button if latest version is newer
1 parent 17fee38 commit 6ee63d9

File tree

1 file changed

+30
-3
lines changed
  • internal_filesystem/builtin/apps/com.example.osupdate/assets

1 file changed

+30
-3
lines changed

internal_filesystem/builtin/apps/com.example.osupdate/assets/osupdate.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@
1414
status_label=None
1515
install_button=None
1616

17+
def compare_versions(ver1: str, ver2: str) -> bool:
18+
"""Compare two version numbers (e.g., '1.2.3' vs '4.5.6').
19+
Returns True if ver1 is greater than ver2, False otherwise."""
20+
print(f"Comparing versions: {ver1} vs {ver2}")
21+
v1_parts = [int(x) for x in ver1.split('.')]
22+
v2_parts = [int(x) for x in ver2.split('.')]
23+
print(f"Version 1 parts: {v1_parts}")
24+
print(f"Version 2 parts: {v2_parts}")
25+
for i in range(max(len(v1_parts), len(v2_parts))):
26+
v1 = v1_parts[i] if i < len(v1_parts) else 0
27+
v2 = v2_parts[i] if i < len(v2_parts) else 0
28+
print(f"Comparing part {i}: {v1} vs {v2}")
29+
if v1 > v2:
30+
print(f"{ver1} is greater than {ver2}")
31+
return True
32+
if v1 < v2:
33+
print(f"{ver1} is less than {ver2}")
34+
return False
35+
print(f"Versions are equal or {ver1} is not greater than {ver2}")
36+
return False
37+
1738

1839
# Custom OTA update with LVGL progress
1940
def update_with_lvgl(url):
@@ -76,9 +97,15 @@ def install_button_click(download_url):
7697

7798
def handle_update_info(version, download_url, changelog):
7899
global install_button, status_label
79-
install_button.remove_flag(lv.obj.FLAG.HIDDEN)
80-
install_button.add_event_cb(lambda e, u=download_url: install_button_click(u), lv.EVENT.CLICKED, None)
81-
status_label.set_text(f"Installed version: {CURRENT_OS_VERSION}\nLatest version: {version}\n\nDetails:\n\n{changelog}")
100+
label = f"Installed OS version: {CURRENT_OS_VERSION}\n"
101+
if compare_versions(version, CURRENT_OS_VERSION):
102+
label += "Available new"
103+
install_button.remove_flag(lv.obj.FLAG.HIDDEN)
104+
install_button.add_event_cb(lambda e, u=download_url: install_button_click(u), lv.EVENT.CLICKED, None)
105+
else:
106+
label += "matches latest"
107+
label += f" version: {version}\n\nDetails:\n\n{changelog}"
108+
status_label.set_text(label)
82109

83110
def show_update_info():
84111
global status_label

0 commit comments

Comments
 (0)