Skip to content

Commit

Permalink
fix:add app name
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 14, 2024
1 parent dd19f58 commit e6788df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 5 additions & 3 deletions ovos_workshop/decorators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import wraps

from typing import Optional
from ovos_utils.log import log_deprecation

from ovos_workshop.decorators.killable import killable_intent, killable_event
Expand Down Expand Up @@ -159,19 +159,21 @@ def real_decorator(func):
return real_decorator


def homescreen_app(icon: str):
def homescreen_app(icon: str, name: Optional[str] = None):
"""
Decorator for adding a method as a homescreen app
the icon file MUST be located under 'gui' subfolder
@param icon: icon file to use in app drawer (relative to "gui" folder)
@param name: short name to show under the icon in app drawer
"""

def real_decorator(func):
# Store the icon inside the function
# This will be used later to call register_homescreen_app
func.homescreen_icon = icon
func.homescreen_app_icon = icon
func.homescreen_app_name = name
return func

return real_decorator
22 changes: 16 additions & 6 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,22 @@ def _register_app_launcher(self):
# register app launcher if registered via decorator
for attr_name in get_non_properties(self):
method = getattr(self, attr_name)
if hasattr(method, 'homescreen_icon'):
event = f"{self.skill_id}.{method.__name__}.homescreen.app"
icon = getattr(method, 'homescreen_icon')
LOG.debug(f"homescreen app registered: {event}")
self.register_homescreen_app(icon=icon, event=event)
if hasattr(method, 'homescreen_app_icon'):
name = getattr(method, 'homescreen_app_name')
event = f"{self.skill_id}.{name or method.__name__}.homescreen.app"
icon = getattr(method, 'homescreen_app_icon')
name = name or self.__skill_id2name
LOG.debug(f"homescreen app registered: {name} - '{event}'")
self.register_homescreen_app(icon=icon,
name=name or self.skill_id,
event=event)
self.add_event(event, method, speak_errors=False)

def __skill_id2name(self) -> str:
"""helper to make a nice string out of a skill_id"""
return (self.skill_id.split(".")[0].replace("_", " ").
replace("-", " ").replace("skill", "").title().strip())

def _init_settings(self):
"""
Set up skill settings. Defines settings in the specified file path,
Expand Down Expand Up @@ -913,7 +922,7 @@ def _init_settings_manager(self):
"""
self.settings_manager = SkillSettingsManager(self)

def register_homescreen_app(self, icon: str, event: str):
def register_homescreen_app(self, icon: str, name: str, event: str):
"""the icon file MUST be located under 'gui' subfolder"""
# this path is hardcoded in ovos_gui.constants and follows XDG spec
# we use it to ensure resource availability between containers
Expand All @@ -927,6 +936,7 @@ def register_homescreen_app(self, icon: str, event: str):
self.bus.emit(Message("homescreen.register.app",
{"skill_id": self.skill_id,
"icon": shared_path,
"name": name,
"event": event}))

def register_resting_screen(self):
Expand Down
4 changes: 0 additions & 4 deletions test/unittests/test_resource_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def test_locate_lang_directories(self):
from ovos_workshop.resource_files import locate_lang_directories
# TODO

def test_resolve_resource_file(self):
from ovos_workshop.resource_files import resolve_resource_file
# TODO

def test_find_resource(self):
from ovos_workshop.resource_files import find_resource
test_dir = join(dirname(__file__), "test_res")
Expand Down

0 comments on commit e6788df

Please sign in to comment.