From 457ffe83865079c61101d0a2b705cd1485a7340b Mon Sep 17 00:00:00 2001 From: Andrii Shafar Date: Mon, 17 Apr 2023 04:31:21 +0300 Subject: [PATCH] fix: multiple links in "final-screen" values results in error (#84) --- tests/example-final-screen.yml | 6 +++++- yafti/screen/title.py | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/example-final-screen.yml b/tests/example-final-screen.yml index c298a99..a636878 100644 --- a/tests/example-final-screen.yml +++ b/tests/example-final-screen.yml @@ -18,7 +18,11 @@ screens: title: "All done" icon: "/path/to/icon" links: - - "Gnome Software": + - "Install More Applications": run: /usr/bin/gnome-software + - "Website": + run: /usr/bin/xdg-open https://ublue.it + - "Join the Discord Community": + run: /usr/bin/xdg-open https://discord.gg/XjG48C7VHx description: | Thanks for installing, join the community, next steps diff --git a/yafti/screen/title.py b/yafti/screen/title.py index 19cefca..2d2faaf 100644 --- a/yafti/screen/title.py +++ b/yafti/screen/title.py @@ -1,4 +1,5 @@ import asyncio +import hashlib from functools import partial from typing import List, Optional @@ -49,7 +50,7 @@ def __init__( description: str = None, icon: str = None, links: List[dict[str, str]] = None, - **kwargs + **kwargs, ): super().__init__(**kwargs) self.status_page.set_title(title) @@ -70,16 +71,21 @@ def append_action_rows(self, links, links_list_box): for link in links: title, action = list(link.items())[0] plugin, config = list(action.items())[0] - events.register("on_action_row_open") - - events.on( - "on_action_row_open", lambda _: self.on_action_row_open(plugin, config) + hash_title = hashlib.md5( + title.encode("utf-8"), usedforsecurity=False + ).hexdigest() + event_name = f"on_action_row_open_{hash_title}" + event_fn = partial( + TitleScreen.on_action_row_open, plugin=plugin, config=config ) + events.register(event_name) + events.on(event_name, event_fn) + def do_emit(*args, **kwargs): asyncio.create_task(events.emit(*args, **kwargs)) - _on_clicked = partial(do_emit, "on_action_row_open") + _on_clicked = partial(do_emit, event_name) link_action_row = Adw.ActionRow() @@ -93,5 +99,8 @@ def do_emit(*args, **kwargs): links_list_box.append(link_action_row) - async def on_action_row_open(self, plugin, config): + @staticmethod + async def on_action_row_open(*args, plugin=None, config=None): + if not plugin and not config: + return await PLUGINS.get(plugin)(config)