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

1from __future__ import annotations 

2 

3from pathlib import Path 

4from typing import TYPE_CHECKING, Any, Literal 

5 

6from .base import Base, add_prop 

7 

8if TYPE_CHECKING: 

9 from collections.abc import Awaitable 

10 

11 from .api import FlowLauncherAPI 

12 

13__all__ = ("PluginMetadata",) 

14 

15 

16class PluginMetadata(Base): 

17 r"""This class represents a plugin's metadata 

18 

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 """ 

44 

45 def __init__(self, data: dict[str, Any], flow_api: FlowLauncherAPI) -> None: 

46 super().__init__(data) 

47 self._flow_api = flow_api 

48 

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") 

71 

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() 

76 

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() 

81 

82 def add_keyword(self, keyword: str) -> Awaitable[None]: 

83 r"""|coro| 

84 

85 Registers a new keyword with flow for the plugin. 

86 

87 This is a shortcut to :func:`~flogin.flow.api.FlowLauncherAPI.add_keyword` 

88 

89 Parameters 

90 -------- 

91 keyword: :class:`str` 

92 The keyword to be added 

93 

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. 

98 

99 Returns 

100 -------- 

101 None 

102 """ 

103 

104 return self._flow_api.add_keyword(self.id, keyword) 

105 

106 def remove_keyword(self, keyword: str) -> Awaitable[None]: 

107 """|coro| 

108 

109 Removes a keyword from the plugin. 

110 

111 This is a shortcut to :func:`~flogin.flow.api.FlowLauncherAPI.remove_keyword` 

112 

113 Parameters 

114 -------- 

115 keyword: :class:`str` 

116 The keyword to be removed 

117 

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. 

122 

123 Returns 

124 -------- 

125 None 

126 """ 

127 

128 return self._flow_api.remove_keyword(self.id, keyword)