Skip to content

Commit

Permalink
fix: delegate to phal plugin
Browse files Browse the repository at this point in the history
dont try to set the wallpaper in the skill, just emit the proper event
  • Loading branch information
JarbasAl committed Nov 15, 2024
1 parent 174c5f8 commit 6a78e08
Showing 1 changed file with 9 additions and 39 deletions.
48 changes: 9 additions & 39 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
from ovos_workshop.decorators import intent_handler, resting_screen_handler
from ovos_workshop.intents import IntentBuilder
from ovos_workshop.skills import OVOSSkill
from wallpaper_changer import set_wallpaper, get_desktop_environment
from wallpaper_changer.search import latest_reddit, latest_wpcraft, \
latest_unsplash
from wallpaper_changer.search import latest_reddit, latest_wpcraft, latest_unsplash


class WallpapersSkill(OVOSSkill):

def initialize(self):
# skill settings defaults
if "auto_detect" not in self.settings:
self.settings["auto_detect"] = True
if "desktop_env" not in self.settings:
self.settings["desktop_env"] = get_desktop_environment()
if "rotate_wallpaper" not in self.settings:
self.settings["rotate_wallpaper"] = True
if "change_mins" not in self.settings:
self.settings["change_mins"] = 30

# imaage sources
# image sources
if "unsplash" not in self.settings:
self.settings["unsplash"] = False
if "wpcraft" not in self.settings:
Expand Down Expand Up @@ -109,9 +103,6 @@ def initialize(self):
self.pic_idx = 0
self.picture_list = []

# events
self.log.info("Detected desktop env " + self.settings["desktop_env"])

# gui slideshow buttons
self.gui.register_handler(f'wallpaper.next', self.handle_next)
self.gui.register_handler(f'wallpaper.prev', self.handle_prev)
Expand Down Expand Up @@ -238,20 +229,10 @@ def iter_wallpapers(self):
yield u["imgLink"]

def change_wallpaper(self, image):
if self.settings["auto_detect"]:
success = set_wallpaper(image)
else:
# allow user override of wallpaper command
success = set_wallpaper(image, self.settings["desktop_env"])
if not success:
success = set_wallpaper(image)

# update in homescreen skill / PHAL plugin
self.bus.emit(Message("ovos.wallpaper.manager.set.wallpaper",
{"provider_name": self.skill_id,
"url": image}))
{"provider_name": self.skill_id, "url": image}))
self.bus.emit(Message("homescreen.wallpaper.set", {"url": image}))
return success

def display(self):
self.gui.clear()
Expand All @@ -268,12 +249,8 @@ def display(self):
@intent_handler("wallpaper.random.intent")
def handle_random_wallpaper(self, message):
image, title = self.update_picture()
success = self.change_wallpaper(image)
if success:
self.speak_dialog("wallpaper.changed")
else:
self.speak_dialog("wallpaper fail")
self.gui.show_image(image, fill='PreserveAspectFit')
self.change_wallpaper(image)
self.speak_dialog("wallpaper.changed")

@intent_handler("picture.random.intent")
def handle_random_picture(self, message=None):
Expand All @@ -288,12 +265,8 @@ def handle_wallpaper_about(self, message):
query = message.data["query"]
self.speak_dialog("searching", {"query": query})
image, title = self.update_picture(query)
success = self.change_wallpaper(image)
if success:
self.speak_dialog("wallpaper.changed")
else:
self.speak_dialog("wallpaper fail")
self.gui.show_image(image, fill='PreserveAspectFit')
self.change_wallpaper(image)
self.speak_dialog("wallpaper.changed")

@intent_handler("picture.about.intent")
def handle_picture_about(self, message=None):
Expand Down Expand Up @@ -336,8 +309,5 @@ def handle_prev(self, message=None):
.require("SlideShow"))
def handle_set_wallpaper(self, message=None):
image = self.picture_list[self.pic_idx]["imgLink"]
success = self.change_wallpaper(image)
if success:
self.speak_dialog("wallpaper.changed")
else:
self.speak_dialog("wallpaper fail")
self.change_wallpaper(image)
self.speak_dialog("wallpaper.changed")

0 comments on commit 6a78e08

Please sign in to comment.