@@ -643,6 +643,7 @@ def __init__(self):
643643 self .installer = installer .Installer ()
644644 self .installer .connect ("appstream-changed" , self .on_appstream_changed )
645645 self .task_cancellable = None
646+ self .addons_cancellable = None
646647 self .current_task = None
647648 self .recursion_buster = False
648649
@@ -946,6 +947,10 @@ def list_header_func(row, before, user_data=None):
946947
947948 self .addons_listbox = self .builder .get_object ("box_addons" )
948949 self .addons_listbox .set_header_func (list_header_func , None )
950+
951+ self .addons_page = self .builder .get_object ("addons_page" )
952+ self .addons_content = self .builder .get_object ("addons_content_frame" )
953+ self .addons_spinner = self .builder .get_object ("addons_spinner" )
949954 self .package_details_listbox = self .builder .get_object ("package_details_listbox" )
950955
951956 self .app_list_stack = self .builder .get_object ("app_list_stack" )
@@ -2295,6 +2300,11 @@ def go_back_action(self):
22952300 XApp .set_window_progress (self .main_window , 0 )
22962301 self .stop_progress_pulse ()
22972302
2303+ if self .addons_cancellable is not None :
2304+ self .addons_cancellable .cancel ()
2305+ self .addons_cancellable = None
2306+ self .addons_spinner .stop ()
2307+
22982308 # If we're still loading details (and simulating), there's no task yet,
22992309 # but we can cancel it via cancellable the installer gave us initially.
23002310 if self .task_cancellable is not None :
@@ -3175,25 +3185,51 @@ def on_installer_info_ready(self, task):
31753185 self .launch_button .hide ()
31763186
31773187 def populate_addons (self , pkginfo ):
3188+ if self .addons_cancellable is not None :
3189+ self .addons_cancellable .cancel ()
3190+ self .addons_cancellable = Gio .Cancellable ()
3191+
31783192 for row in self .addons_listbox .get_children ():
31793193 row .destroy ()
31803194
3195+ self .addons_content .hide ()
3196+ self .addons_spinner .show ()
3197+ self .addons_spinner .start ()
3198+ self .addons_page .show ()
3199+
3200+ thread = threading .Thread (
3201+ target = self ._populate_addons_thread ,
3202+ args = (pkginfo , self .addons_cancellable ),
3203+ daemon = True ,
3204+ )
3205+ thread .start ()
3206+
3207+ def _populate_addons_thread (self , pkginfo , cancellable ):
31813208 addons = self .installer .get_addons (pkginfo )
3182- if addons is None :
3183- self .builder .get_object ("addons_page" ).hide ()
3184- return
3209+ if addons :
3210+ addons .sort (key = lambda a : a .get_display_name ().casefold ())
3211+ GLib .idle_add (self ._populate_addons_finished , pkginfo , addons , cancellable )
3212+
3213+ def _populate_addons_finished (self , pkginfo , addons , cancellable ):
3214+ if cancellable .is_cancelled ():
3215+ return False
3216+
3217+ self .addons_spinner .stop ()
3218+ self .addons_spinner .hide ()
3219+
3220+ if not addons :
3221+ self .addons_page .hide ()
3222+ return False
31853223
31863224 name_size_group = Gtk .SizeGroup (mode = Gtk .SizeGroupMode .HORIZONTAL )
31873225 button_size_group = Gtk .SizeGroup (mode = Gtk .SizeGroupMode .HORIZONTAL )
31883226
3189- first = True
31903227 for addon in addons :
3191- print ("Discovered addon: %s" % addon .name )
3192- first = False
3193-
31943228 row = FlatpakAddonRow (self , pkginfo , addon , name_size_group , button_size_group )
31953229 self .addons_listbox .insert (row , - 1 )
3196- self .builder .get_object ("addons_page" ).show_all ()
3230+
3231+ self .addons_content .show_all ()
3232+ return False
31973233
31983234 def on_installer_progress (self , pkginfo , progress , estimating , status_text = None ):
31993235 if self .current_pkginfo is not None and self .current_pkginfo .name == pkginfo .name :
0 commit comments