Coverage for flogin/flow/plugin_metadata.py: 100%
30 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-03 22:51 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-03 22:51 +0000
1from __future__ import annotations
3from pathlib import Path
4from typing import TYPE_CHECKING, Any, Literal
6from .base import Base, add_prop
8if TYPE_CHECKING:
9 from collections.abc import Awaitable
11 from .api import FlowLauncherAPI
13__all__ = ("PluginMetadata",)
16class PluginMetadata(Base):
17 r"""This class represents a plugin's metadata
19 Attributes
20 --------
21 id: :class:`str`
22 The plugin's ID
23 name: :class:`str`
24 The plugin's name
25 author: :class:`str`
26 The name of the plugin's author
27 version: :class:`str`
28 The current version of the plugin
29 language: :class:`str`
30 The language that the plugin is written in. Possible values: "csharp", "executable", "fsharp", "python", "javascript", "typescript", "python_v2", "executable_v2", "javascript_v2", "typescript_v2".
31 description: :class:`str`
32 The plugin's description
33 website: :class:`str`
34 A link to the plugin's website
35 disabled: :class:`bool`
36 Whether the plugin is disabled or not
37 directory: :class:`str`
38 The path to the plugin's directory
39 keywords: list[:class:`str`]
40 A list of the plugin's keywords
41 main_keyword: :class:`str`
42 The plugin's main keyword
43 """
45 def __init__(self, data: dict[str, Any], flow_api: FlowLauncherAPI) -> None:
46 super().__init__(data)
47 self._flow_api = flow_api
49 id: str = add_prop("id")
50 name: str = add_prop("name")
51 author: str = add_prop("author")
52 version: str = add_prop("version")
53 language: Literal[
54 "csharp",
55 "executable",
56 "fsharp",
57 "python",
58 "javascript",
59 "typescript",
60 "python_v2",
61 "executable_v2",
62 "javascript_v2",
63 "typescript_v2",
64 ] = add_prop("language")
65 description: str = add_prop("description")
66 website: str = add_prop("website")
67 disabled: bool = add_prop("disabled")
68 directory: str = add_prop("pluginDirectory")
69 keywords: list[str] = add_prop("actionKeywords")
70 main_keyword: str = add_prop("actionKeyword")
72 @property
73 def executable(self) -> Path:
74 r""":class:`pathlib.Path`: The path to the plugin's executable file"""
75 return Path(self._data["executeFilePath"]).absolute()
77 @property
78 def icon(self) -> Path:
79 r""":class:`pathlib.Path`: The path to the plugin's icon file"""
80 return Path(self._data["icoPath"]).absolute()
82 def add_keyword(self, keyword: str) -> Awaitable[None]:
83 r"""|coro|
85 Registers a new keyword with flow for the plugin.
87 This is a shortcut to :func:`~flogin.flow.api.FlowLauncherAPI.add_keyword`
89 Parameters
90 --------
91 keyword: :class:`str`
92 The keyword to be added
94 Raises
95 -------
96 :class:`~flogin.jsonrpc.errors.JsonRPCException`
97 This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
99 Returns
100 --------
101 None
102 """
104 return self._flow_api.add_keyword(self.id, keyword)
106 def remove_keyword(self, keyword: str) -> Awaitable[None]:
107 """|coro|
109 Removes a keyword from the plugin.
111 This is a shortcut to :func:`~flogin.flow.api.FlowLauncherAPI.remove_keyword`
113 Parameters
114 --------
115 keyword: :class:`str`
116 The keyword to be removed
118 Raises
119 -------
120 :class:`~flogin.jsonrpc.errors.JsonRPCException`
121 This is raised when an error happens with the JsonRPC pipe while attempting to call this API method.
123 Returns
124 --------
125 None
126 """
128 return self._flow_api.remove_keyword(self.id, keyword)