Skip to content

Commit

Permalink
fix: multiple links in "final-screen" values results in error (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reidond authored Apr 17, 2023
1 parent 6bc6267 commit 457ffe8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 5 additions & 1 deletion tests/example-final-screen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 16 additions & 7 deletions yafti/screen/title.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import hashlib
from functools import partial
from typing import List, Optional

Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -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)

0 comments on commit 457ffe8

Please sign in to comment.