initial push
This commit is contained in:
@@ -15,13 +15,14 @@ class ManifestProcessor(Exception):
|
||||
|
||||
|
||||
class Plugin:
|
||||
path: str = None
|
||||
name: str = None
|
||||
author: str = None
|
||||
version: str = None
|
||||
support: str = None
|
||||
requests:{} = None
|
||||
reference: type = None
|
||||
path: str = None
|
||||
name: str = None
|
||||
author: str = None
|
||||
version: str = None
|
||||
support: str = None
|
||||
requests:{} = None
|
||||
reference: type = None
|
||||
pre_launch: bool = False
|
||||
|
||||
|
||||
class ManifestProcessor:
|
||||
@@ -46,23 +47,25 @@ class ManifestProcessor:
|
||||
plugin.support = self._manifest["support"]
|
||||
plugin.requests = self._manifest["requests"]
|
||||
|
||||
if "pre_launch" in self._manifest.keys():
|
||||
plugin.pre_launch = True if self._manifest["pre_launch"] == "true" else False
|
||||
|
||||
return plugin
|
||||
|
||||
def get_loading_data(self):
|
||||
loading_data = {}
|
||||
requests = self._plugin.requests
|
||||
keys = requests.keys()
|
||||
|
||||
if "pass_events" in keys:
|
||||
if "pass_events" in requests:
|
||||
if requests["pass_events"] in ["true"]:
|
||||
loading_data["pass_events"] = True
|
||||
|
||||
if "bind_keys" in keys:
|
||||
if isinstance(requests["bind_keys"], list):
|
||||
loading_data["bind_keys"] = requests["bind_keys"]
|
||||
|
||||
if "pass_ui_objects" in keys:
|
||||
if "pass_ui_objects" in requests:
|
||||
if isinstance(requests["pass_ui_objects"], list):
|
||||
loading_data["pass_ui_objects"] = [ self._builder.get_object(obj) for obj in requests["pass_ui_objects"] ]
|
||||
|
||||
if "bind_keys" in requests:
|
||||
if isinstance(requests["bind_keys"], list):
|
||||
loading_data["bind_keys"] = requests["bind_keys"]
|
||||
|
||||
return self._plugin, loading_data
|
||||
|
@@ -10,6 +10,7 @@ from os.path import isdir
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
@@ -35,11 +36,23 @@ class PluginsController:
|
||||
|
||||
self._plugins_dir_watcher = None
|
||||
self._plugin_collection = []
|
||||
self._plugin_manifests = {}
|
||||
|
||||
self._load_manifests()
|
||||
|
||||
|
||||
def launch_plugins(self) -> None:
|
||||
def _load_manifests(self):
|
||||
logger.info(f"Loading manifests...")
|
||||
|
||||
for path, folder in [[join(self._plugins_path, item), item] if os.path.isdir(join(self._plugins_path, item)) else None for item in os.listdir(self._plugins_path)]:
|
||||
manifest = ManifestProcessor(path, self._builder)
|
||||
self._plugin_manifests[path] = {
|
||||
"path": path,
|
||||
"folder": folder,
|
||||
"manifest": manifest
|
||||
}
|
||||
|
||||
self._set_plugins_watcher()
|
||||
self.load_plugins()
|
||||
|
||||
def _set_plugins_watcher(self) -> None:
|
||||
self._plugins_dir_watcher = Gio.File.new_for_path(self._plugins_path) \
|
||||
@@ -52,21 +65,47 @@ class PluginsController:
|
||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||
self.reload_plugins(file)
|
||||
|
||||
def load_plugins(self, file: str = None) -> None:
|
||||
logger.info(f"Loading plugins...")
|
||||
def pre_launch_plugins(self) -> None:
|
||||
logger.info(f"Loading pre-launch plugins...")
|
||||
plugin_manifests: {} = {}
|
||||
|
||||
for key in self._plugin_manifests:
|
||||
target_manifest = self._plugin_manifests[key]["manifest"]
|
||||
if target_manifest.is_pre_launch():
|
||||
plugin_manifests[key] = self._plugin_manifests[key]
|
||||
|
||||
self._load_plugins(plugin_manifests, is_pre_launch = True)
|
||||
|
||||
def post_launch_plugins(self) -> None:
|
||||
logger.info(f"Loading post-launch plugins...")
|
||||
plugin_manifests: {} = {}
|
||||
|
||||
for key in self._plugin_manifests:
|
||||
target_manifest = self._plugin_manifests[key]["manifest"]
|
||||
if not target_manifest.is_pre_launch():
|
||||
plugin_manifests[key] = self._plugin_manifests[key]
|
||||
|
||||
self._load_plugins(plugin_manifests)
|
||||
|
||||
def _load_plugins(self, plugin_manifests: {} = {}, is_pre_launch: bool = False) -> None:
|
||||
parent_path = os.getcwd()
|
||||
|
||||
for path, folder in [[join(self._plugins_path, item), item] if os.path.isdir(join(self._plugins_path, item)) else None for item in os.listdir(self._plugins_path)]:
|
||||
try:
|
||||
target = join(path, "plugin.py")
|
||||
manifest = ManifestProcessor(path, self._builder)
|
||||
for key in plugin_manifests:
|
||||
target_manifest = plugin_manifests[key]
|
||||
path, folder, manifest = target_manifest["path"], target_manifest["folder"], target_manifest["manifest"]
|
||||
|
||||
try:
|
||||
target = join(path, "plugin.py")
|
||||
if not os.path.exists(target):
|
||||
raise InvalidPluginException("Invalid Plugin Structure: Plugin doesn't have 'plugin.py'. Aboarting load...")
|
||||
|
||||
plugin, loading_data = manifest.get_loading_data()
|
||||
module = self.load_plugin_module(path, folder, target)
|
||||
self.execute_plugin(module, plugin, loading_data)
|
||||
|
||||
if is_pre_launch:
|
||||
self.execute_plugin(module, plugin, loading_data)
|
||||
else:
|
||||
GLib.idle_add(self.execute_plugin, *(module, plugin, loading_data))
|
||||
except Exception as e:
|
||||
logger.info(f"Malformed Plugin: Not loading -->: '{folder}' !")
|
||||
logger.debug("Trace: ", traceback.print_exc())
|
||||
|
Reference in New Issue
Block a user