Skip to content

Commit

Permalink
frontend: make taskmanager load processes async
Browse files Browse the repository at this point in the history
also closes #2981
  • Loading branch information
mirkobrombin committed Aug 5, 2023
1 parent 40abe2a commit 6f74949
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
4 changes: 3 additions & 1 deletion bottles/frontend/views/bottle_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
52 changes: 31 additions & 21 deletions bottles/frontend/views/bottle_taskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f74949

Please sign in to comment.