Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gui extensions homescreen init #281

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions ovos_plugin_manager/templates/gui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
from typing import Optional, Dict, Any

from ovos_bus_client import Message
from ovos_bus_client import MessageBusClient
from ovos_bus_client.apis.gui import GUIInterface
from ovos_utils.log import LOG
from ovos_config import Configuration
from ovos_utils.log import LOG

try:
from ovos_gui.homescreen import HomescreenManager
except ImportError as _exc:

class HomescreenManager:
"""Fallback class when ovos-gui is not installed.

Raises the original ImportError when instantiated to
provide clear error messaging while still allowing type hints to work.
"""

def __init__(self, *args, **kwargs):
LOG.error("you seem to be running GUIExtensions without ovos-gui installed...")
# raise the original ImportError
raise _exc


class GUIExtension:
Expand All @@ -20,39 +38,40 @@ class GUIExtension:
permanent (bool): disable unloading of GUI skills on gui client disconnections
"""

def __init__(self, config, bus=None, gui=None,
preload_gui=False, permanent=False):
def __init__(self, config: Dict[str, Any],
bus: Optional[MessageBusClient] = None,
gui: Optional[GUIInterface] = None,
preload_gui: bool = False,
permanent: bool = False):

if not bus:
bus = MessageBusClient()
bus.run_in_thread()
bus.connected_event.wait()
self.bus = bus
self.gui = gui or GUIInterface("ovos.shell", bus=self.bus,
config=Configuration().get("gui", {}))
self.bus: MessageBusClient = bus
self.gui: GUIInterface = gui or GUIInterface("ovos.shell", bus=self.bus,
config=Configuration().get("gui", {}))
self.preload_gui = preload_gui
self.permanent = permanent
self.config = config
self.homescreen_manager: Optional[HomescreenManager] = None
self.register_bus_events()

def register_bus_events(self):
self.bus.on("mycroft.gui.screen.close", self.handle_remove_namespace)

def bind_homescreen(self, homescreen=None):
def bind_homescreen(self, homescreen: Optional[HomescreenManager] = None):
if self.config.get("homescreen_supported", False):
if not homescreen:
# raise exception as usual if this fails
from ovos_gui.homescreen import HomescreenManager
homescreen = HomescreenManager(self.bus, self.gui)
LOG.debug("Loading HomescreenManager")
homescreen = HomescreenManager(self.bus)
homescreen.daemon = True
homescreen.start()

self.homescreen_manager = homescreen
else:
LOG.info("Homescreen support not configured")

def handle_remove_namespace(self, message):
LOG.info("Got Clear Namespace Event In Skill")
def handle_remove_namespace(self, message: Message):
get_skill_namespace = message.data.get("skill_id", "")
if get_skill_namespace:
self.bus.emit(Message("gui.clear.namespace",
Expand Down
Loading