@@ -42,28 +42,31 @@ def load_icon(icon_path):
4242# Check and collect subdirectories from existing directories
4343apps_dir = "/apps"
4444apps_dir_builtin = "/builtin/apps"
45- app_dirs = []
4645seen_base_names = set ()
46+ app_list = []
4747
48- # Check and collect unique subdirectories from existing directories
48+ # Check and collect unique subdirectories
4949for dir_path in [apps_dir , apps_dir_builtin ]:
5050 try :
51- if uos .stat (dir_path )[0 ] & 0x4000 : # Verify directory exists and is a directory
52- for d in uos .listdir (dir_path ): # Iterate over subdirectories
51+ if uos .stat (dir_path )[0 ] & 0x4000 : # Verify directory exists
52+ for d in uos .listdir (dir_path ):
5353 full_path = f"{ dir_path } /{ d } "
54- if uos .stat (full_path )[0 ] & 0x4000 : # Check if it's a directory
55- base_name = d # Extract base name (e.g., 'example' from '/apps/example')
56- if base_name not in seen_base_names : # Only add if base name hasn't been seen (no duplicates)
57- app_dirs .append (full_path )
54+ if uos .stat (full_path )[0 ] & 0x4000 : # Check if it's a directory
55+ base_name = d
56+ if base_name not in seen_base_names : # Avoid duplicates
5857 seen_base_names .add (base_name )
58+ app = parse_manifest (f"{ full_path } /META-INF/MANIFEST.JSON" )
59+ if app .category != "launcher" : # Skip launchers
60+ app_list .append ((app .name , full_path ))
5961 except OSError :
60- # Skip if directory doesn't exist or isn't accessible
6162 pass
6263
63- # Should we skip 'Launcher' apps from the list here?
64- for app_dir_fullpath in app_dirs :
65- app = parse_manifest (f"{ app_dir_fullpath } /META-INF/MANIFEST.JSON" )
66- # Create a container for each app (icon + label)
64+ # Sort apps alphabetically by app.name
65+ app_list .sort (key = lambda x : x [0 ].lower ()) # Case-insensitive sorting
66+
67+ # Create UI for each app
68+ for app_name , app_dir_fullpath in app_list :
69+ # Create container for each app (icon + label)
6770 app_cont = lv .obj (cont )
6871 app_cont .set_size (iconcont_width , iconcont_height )
6972 app_cont .set_style_border_width (0 , 0 )
@@ -80,17 +83,16 @@ def load_icon(icon_path):
8083 image .set_src (load_icon (icon_path ))
8184 except Exception as e :
8285 print (f"Error loading default icon { icon_path } : { e } - using symbol" )
83- image .set_src (lv .SYMBOL .STOP ) # square block
86+ image .set_src (lv .SYMBOL .STOP )
8487 image .align (lv .ALIGN .TOP_MID , 0 , 0 )
8588 image .set_size (icon_size , icon_size )
86- # Create label
8789 label = lv .label (app_cont )
88- label .set_text (app . name )
90+ label .set_text (app_name ) # Use app_name directly
8991 label .set_long_mode (lv .label .LONG .WRAP )
9092 label .set_width (iconcont_width )
9193 label .align (lv .ALIGN .BOTTOM_MID , 0 , 0 )
9294 label .set_style_text_align (lv .TEXT_ALIGN .CENTER , 0 )
93- app_cont .add_event_cb (lambda e , app_dir_fullpath = app_dir_fullpath : start_app (app_dir_fullpath ), lv .EVENT .CLICKED , None )
95+ app_cont .add_event_cb (lambda e , path = app_dir_fullpath : start_app (path ), lv .EVENT .CLICKED , None )
9496
9597end = time .ticks_ms ()
9698print (f"Displaying all icons took: { end - start } ms" )
0 commit comments