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

skill loading requirements continued #272

Merged
merged 22 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 20 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
3 changes: 2 additions & 1 deletion mycroft/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self, skill):

@property
def bus(self):
return self.skill.bus
if self.skill:
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
return self.skill.bus

@property
def skill_id(self):
Expand Down
3 changes: 3 additions & 0 deletions mycroft/gui/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def open(self):
def on_close(self):
LOG.info('Closing {}'.format(id(self)))
GUIWebsocketHandler.clients.remove(self)
if len(GUIWebsocketHandler.clients) == 0:
message = Message("mycroft.gui.unavailable")
self.application.enclosure.core_bus.emit(message)

def synchronize(self):
""" Upload namespaces, pages and data to the last connected. """
Expand Down
86 changes: 73 additions & 13 deletions mycroft/gui/extensions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import threading

from ovos_config.config import Configuration

from mycroft.gui.homescreen import HomescreenManager
from mycroft.gui.interfaces.mobile import MobileExtensionGuiInterface
from mycroft.gui.interfaces.smartspeaker import SmartSpeakerExtensionGuiInterface
from mycroft.messagebus import Message
from mycroft.util.log import LOG
from ovos_backend_client.pairing import is_paired
from ovos_utils.system import ssh_enable, ssh_disable

from mycroft.gui.homescreen import HomescreenManager
from mycroft.gui.interfaces.smartspeaker import SmartSpeakerExtensionGuiInterface
from mycroft.gui.interfaces.mobile import MobileExtensionGuiInterface

class ExtensionsManager:
def __init__(self, name, bus, gui):
Expand All @@ -28,7 +29,7 @@ def __init__(self, name, bus, gui):
self.active_extension = enclosure_config.get("extension", "generic")

# ToDo: Add Exclusive Support For "Desktop", "Mobile" Extensions
self.supported_extensions = ["smartspeaker", "bigscreen", "generic", "mobile"]
self.supported_extensions = ["smartspeaker", "bigscreen", "generic", "mobile", "plasmoid"]

if self.active_extension.lower() not in self.supported_extensions:
self.active_extension = "generic"
Expand All @@ -47,29 +48,42 @@ def activate_extension(self, extension_id):
self.extension = BigscreenExtension(self.bus, self.gui)
elif extension_id == "mobile":
self.extension = MobileExtension(self.bus, self.gui)
elif extension_id == "plasmoid":
self.extension = PlasmoidExtension(self.bus, self.gui)
else:
self.extension = GenericExtension(self.bus, self.gui)

LOG.info(f"Extensions Manager: Activated Extension {extension_id}")
self.bus.emit(
Message("extension.manager.activated", {"id": extension_id}))

def signal_available(message=None):
message = message or Message("")
self.bus.emit(message.forward("mycroft.gui.available",
{"permanent": self.extension.permanent}))

if self.extension.preload_gui:
signal_available()
else:
self.bus.on("mycroft.gui.connected", signal_available)
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved


class SmartSpeakerExtension:
""" Smart Speaker Extension: This extension is responsible for managing the Smart Speaker
specific GUI behaviours. This extension adds support for Homescreens and Homescreen Mangement.

Args:
name: Name of the extension manager
bus: MessageBus instance
gui: GUI instance
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
"""

def __init__(self, bus, gui):
def __init__(self, bus, gui, preload_gui=False, permanent=True):
LOG.info("SmartSpeaker: Initializing")

self.bus = bus
self.gui = gui
self.preload_gui = preload_gui
self.permanent = permanent
self.homescreen_manager = HomescreenManager(self.bus, self.gui)

self.homescreen_thread = threading.Thread(
Expand Down Expand Up @@ -135,16 +149,17 @@ class BigscreenExtension:
support for Window managment and Window behaviour.

Args:
name: Name of the extension manager
bus: MessageBus instance
gui: GUI instance
"""

def __init__(self, bus, gui):
def __init__(self, bus, gui, preload_gui=False, permanent=True):
LOG.info("Bigscreen: Initializing")

self.bus = bus
self.gui = gui
self.permanent = permanent
self.preload_gui = preload_gui
self.interaction_without_idle = True
self.interaction_skill_id = None

Expand Down Expand Up @@ -205,16 +220,17 @@ class GenericExtension:
Management but it needs to be exclusively enabled in the configuration file.

Args:
name: Name of the extension manager
bus: MessageBus instance
gui: GUI instance
"""

def __init__(self, bus, gui):
def __init__(self, bus, gui, preload_gui=False, permanent=False):
LOG.info("Generic: Initializing")

self.bus = bus
self.gui = gui
self.preload_gui = preload_gui
self.permanent = permanent
core_config = Configuration()
gui_config = core_config.get("gui") or {}
generic_config = gui_config.get("generic", {})
Expand Down Expand Up @@ -246,16 +262,17 @@ class MobileExtension:
This extension adds support for Homescreens and Homescreen Management and global page back navigation.

Args:
name: Name of the extension manager
bus: MessageBus instance
gui: GUI instance
"""

def __init__(self, bus, gui):
def __init__(self, bus, gui, preload_gui=True, permanent=True):
LOG.info("Mobile: Initializing")

self.bus = bus
self.gui = gui
self.preload_gui = preload_gui
self.permanent = permanent
self.homescreen_manager = HomescreenManager(self.bus, self.gui)

self.homescreen_thread = threading.Thread(
Expand All @@ -280,3 +297,46 @@ def force_home(self, message):

def handle_page_back(self, message):
self.gui.handle_namespace_global_back({})


class PlasmoidExtension:
""" Plasmoid Platform Extension: This extension is responsible for managing the generic GUI behaviours
for non specific platforms. The generic extension does optionally support Homescreen and Homescreen
Management but it needs to be exclusively enabled in the configuration file.

Args:
bus: MessageBus instance
gui: GUI instance
"""

def __init__(self, bus, gui, preload_gui=False, permanent=True):
LOG.info("Plasmoid: Initializing")

self.bus = bus
self.gui = gui
self.preload_gui = preload_gui
self.permanent = permanent
core_config = Configuration()
gui_config = core_config.get("gui") or {}
generic_config = gui_config.get("plasmoid", {})
self.homescreen_supported = generic_config.get("homescreen_supported", False)

if self.homescreen_supported:
self.homescreen_manager = HomescreenManager(self.bus, self.gui)
self.homescreen_thread = threading.Thread(
target=self.homescreen_manager.run)
self.homescreen_thread.start()

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

except Exception as e:
LOG.error(f"Plasmoid: Init Bus Exception: {e}")

def handle_remove_namespace(self, message):
LOG.info("Got Clear Namespace Event In Skill")
get_skill_namespace = message.data.get("skill_id", "")
if get_skill_namespace:
self.bus.emit(Message("gui.clear.namespace",
{"__from": get_skill_namespace}))
12 changes: 6 additions & 6 deletions mycroft/skills/skill_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import importlib
import os
import sys
from inspect import isclass, signature
from inspect import isclass
from os import path, makedirs
from time import time

from ovos_config.locations import get_xdg_data_dirs, get_xdg_data_save_path
from ovos_config.meta import get_xdg_base
from ovos_plugin_manager.skills import find_skill_plugins
from ovos_workshop.skills.base import SkillNetworkRequirements, BaseSkill
from ovos_workshop.skills.base import BaseSkill
from ovos_utils.process_utils import RuntimeRequirements
from ovos_config.config import Configuration
from mycroft.messagebus import Message
from mycroft.skills.mycroft_skill.mycroft_skill import MycroftSkill
Expand Down Expand Up @@ -361,10 +361,10 @@ def skill_class(self, val):
self._skill_class = val

@property
def network_requirements(self):
def runtime_requirements(self):
if not self.skill_class:
return SkillNetworkRequirements()
return self.skill_class.network_requirements
return RuntimeRequirements()
return self.skill_class.runtime_requirements

@property
def is_blacklisted(self):
Expand Down
Loading