From 6f74949b7a3fad92605897a43d3f15fa1a534619 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Sat, 5 Aug 2023 13:20:23 +0200 Subject: [PATCH] frontend: make taskmanager load processes async also closes #2981 --- bottles/frontend/views/bottle_details.py | 4 +- bottles/frontend/views/bottle_taskmanager.py | 52 ++++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/bottles/frontend/views/bottle_details.py b/bottles/frontend/views/bottle_details.py index 550d5d81cf..4986e4732f 100644 --- a/bottles/frontend/views/bottle_details.py +++ b/bottles/frontend/views/bottle_details.py @@ -109,6 +109,7 @@ def __init__(self, details, config, **kwargs): self.manager = details.window.manager self.stack_bottle = details.stack_bottle self.leaflet = details.leaflet + self.details = details self.config = config self.show_hidden = False @@ -149,7 +150,6 @@ def __init__(self, details, config, **kwargs): "flatpak/black-screen-or-silent-crash" ) - if "FLATPAK_ID" in os.environ: ''' If Flatpak, show the btn_flatpak_doc widget to reach @@ -162,6 +162,8 @@ def __change_page(self, _widget, page_name): This function try to change the page based on user choice, if the page is not available, it will show the "bottle" page. """ + if page_name == "taskmanager": + self.details.view_taskmanager.update(config=self.config) try: self.stack_bottle.set_visible_child_name(page_name) self.leaflet.navigate(Adw.NavigationDirection.FORWARD) diff --git a/bottles/frontend/views/bottle_taskmanager.py b/bottles/frontend/views/bottle_taskmanager.py index 147129b51c..05fea645e3 100644 --- a/bottles/frontend/views/bottle_taskmanager.py +++ b/bottles/frontend/views/bottle_taskmanager.py @@ -88,29 +88,39 @@ def update(self, widget=False, config: Optional[BottleConfig] = None): This function scan for new processed and update the liststore_processes with the new data """ - if config is None: - config = BottleConfig() - self.config = config - if not config.Runner: - return - self.liststore_processes.clear() - winebridge = WineBridge(config) - if winebridge.is_available(): - processes = winebridge.get_procs() - else: - winedbg = WineDbg(config) - processes = winedbg.get_processes() - - if len(processes) > 0: - for process in processes: - self.liststore_processes.append([ - process.get("pid"), - process.get("name", "n/a"), - process.get("threads", "0"), - # process.get("parent", "0") - ]) + def fetch_processes(config: Optional[BottleConfig] = None): + if config is None: + config = BottleConfig() + self.config = config + if not config.Runner: + return + + winebridge = WineBridge(config) + + if winebridge.is_available(): + processes = winebridge.get_procs() + else: + winedbg = WineDbg(config) + processes = winedbg.get_processes() + return processes + + def update_processes(processes: list, *_args): + if len(processes) > 0: + for process in processes: + self.liststore_processes.append([ + process.get("pid"), + process.get("name", "n/a"), + process.get("threads", "0"), + # process.get("parent", "0") + ]) + + RunAsync( + task_func=fetch_processes, + callback=update_processes, + config=config + ) def sensitive_update(self, widget): @GtkUtils.run_in_main_loop