diff --git a/.gitignore b/.gitignore index d4dcb8b..0b6e87f 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,4 @@ cython_debug/ .vscode test.py +.history/ \ No newline at end of file diff --git a/pyflowlauncher/manifest.py b/pyflowlauncher/manifest.py new file mode 100644 index 0000000..a7bb457 --- /dev/null +++ b/pyflowlauncher/manifest.py @@ -0,0 +1,25 @@ +from typing import TypedDict, Literal + +MANIFEST_FILE = 'plugin.json' + +Languages = Literal[ + 'Python', + 'CSharp', + 'FSharp', + 'Executable', + 'TypeScript', + 'JavaScript', +] + + +class PluginManifestSchema(TypedDict): + ID: str + ActionKeyword: str + Name: str + Description: str + Author: str + Version: str + Language: Languages + Website: str + IcoPath: str + ExecuteFileName: str diff --git a/pyflowlauncher/plugin.py b/pyflowlauncher/plugin.py index 5365ca1..0064c33 100644 --- a/pyflowlauncher/plugin.py +++ b/pyflowlauncher/plugin.py @@ -1,13 +1,17 @@ from __future__ import annotations +import sys from functools import wraps from typing import Any, Callable, Iterable, Union +from pathlib import Path +import json from pyflowlauncher.shared import logger from .event import EventHandler from .jsonrpc import JsonRPCClient from .result import JsonRPCAction, ResultResponse +from .manifest import PluginManifestSchema, MANIFEST_FILE Method = Callable[..., Union[ResultResponse, JsonRPCAction]] @@ -54,3 +58,13 @@ def run(self) -> None: if 'result' in feedback and self._settings is not None: feedback['SettingsChange'] = self.settings self._client.send(feedback) + + def plugin_root_dir(self) -> Path: + """Return the root directory of the plugin.""" + return Path(sys.argv[0]).parent + + def manifest(self) -> PluginManifestSchema: + """Return the plugin manifest.""" + with open(self.plugin_root_dir() / MANIFEST_FILE, 'r', encoding='utf-8') as f: + manifest = json.load(f) + return manifest