Skip to content

Commit

Permalink
Merge pull request #1 from Garulf/feat-plugin-manifest
Browse files Browse the repository at this point in the history
Feat plugin manifest
  • Loading branch information
Garulf authored Jan 1, 2024
2 parents e15b14b + c0feee4 commit c64d8bd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ cython_debug/
.vscode

test.py
.history/
25 changes: 25 additions & 0 deletions pyflowlauncher/manifest.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions pyflowlauncher/plugin.py
Original file line number Diff line number Diff line change
@@ -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]]

Expand Down Expand Up @@ -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

0 comments on commit c64d8bd

Please sign in to comment.