Skip to content

Commit

Permalink
fix:improve init (#22)
Browse files Browse the repository at this point in the history
dont block skill loading waiting for wallpaper download, do it async
  • Loading branch information
JarbasAl authored Nov 17, 2024
1 parent 411f234 commit 0d75db5
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ovos_bus_client.message import Message
from ovos_utils.log import LOG
from ovos_utils.xdg_utils import xdg_data_home

from ovos_workshop.decorators import intent_handler
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.skills import OVOSSkill
Expand Down Expand Up @@ -47,26 +48,14 @@ def initialize(self):
# state trackers
self.pic_idx = 0
self.picture_list = []
self.register_with_PHAL()

def fetch_wallpapers(self, query=None) -> str:
self.picture_list = get_wallpapers(query)
self.pic_idx = 0
self.set_context("SlideShow")
return self.picture_list[self.pic_idx]

# PHAL wallpaper manager integrations
def register_with_PHAL(self):
self.bus.emit(Message("ovos.wallpaper.manager.register.provider",
{"provider_name": self.skill_id,
"provider_display_name": self.name}))
self.bus.on(f"{self.skill_id}.get.wallpaper.collection", self.handle_wallpaper_scan)
self.bus.on(f"{self.skill_id}.get.new.wallpaper", self.handle_wallpaper_get)
self.fetch_wallpapers()
self.bus.emit(Message("ovos.wallpaper.manager.collect.collection.response",
{"provider_name": self.skill_id,
"wallpaper_collection": self.picture_list}))
self.add_event(f"{self.skill_id}.get.wallpaper.collection", self.handle_wallpaper_scan)
self.add_event(f"{self.skill_id}.get.new.wallpaper", self.handle_wallpaper_get)
self.bus.emit(Message(f"{self.skill_id}.get.wallpaper.collection")) # download wallpapers on launch

# PHAL wallpaper manager integrations
def handle_wallpaper_scan(self, message: Message):
self.fetch_wallpapers()
self.bus.emit(message.reply("ovos.wallpaper.manager.collect.collection.response",
Expand All @@ -80,6 +69,12 @@ def handle_wallpaper_get(self, message: Message):
"url": url}))

# skill internals
def fetch_wallpapers(self, query=None) -> str:
self.picture_list = get_wallpapers(query)
self.pic_idx = 0
self.set_context("SlideShow")
return self.picture_list[self.pic_idx]

def change_wallpaper(self, image):
# update in homescreen skill / PHAL plugin
self.bus.emit(Message("ovos.wallpaper.manager.set.wallpaper",
Expand Down

0 comments on commit 0d75db5

Please sign in to comment.