Display overview of loaded plugins

This commit is contained in:
Mark Qvist 2024-03-29 18:19:35 +01:00
parent 10329932a9
commit 094cfdb8b5
3 changed files with 91 additions and 9 deletions

View File

@ -3822,12 +3822,14 @@ class SidebandApp(MDApp):
self.bind_clipboard_actions(self.plugins_screen.ids)
self.plugins_screen.ids.plugins_scrollview.effect_cls = ScrollEffect
info = "You can extend Sideband functionality with command and service plugins. This lets you to add your own custom functionality, or add community-developed features.\n\n"
info += "[b]Take extreme caution![/b]\nIf you add a plugin that you did not write yourself, make [b]absolutely[/b] sure you know what it is doing! Loaded plugins have full access to your Sideband application, and should only be added if you are completely certain they are trustworthy.\n\n"
info += "Command plugins allow you to define custom commands that can be carried out in response to LXMF command messages, and they can respond with any kind of information or data to the requestor (or to any LXMF address).\n\n"
info += "By using service plugins, you can start additional services or programs within the Sideband application context, that other plugins (or Sideband itself) can interact with."
info += "Restart Sideband for changes to these settings to take effect."
self.plugins_screen.ids.plugins_info.text = info
info1 = "You can extend Sideband functionality with command and service plugins. This lets you to add your own custom functionality, or add community-developed features.\n"
info2 = "[b]Take extreme caution![/b]\nIf you add a plugin that you did not write yourself, make [b]absolutely[/b] sure you know what it is doing! Loaded plugins have full access to your Sideband application, and should only be added if you are completely certain they are trustworthy.\n\n"
info2 += "[i]Command Plugins[/i] allow you to define custom commands that can be carried out in response to LXMF command messages, and they can respond with any kind of information or data to the requestor (or to any LXMF address).\n\n"
info2 += "By using [i]Service Plugins[/i], you can start additional services or programs within the Sideband application context, that other plugins (or Sideband itself) can interact with.\n\n"
info2 += "With [i]Telemetry Plugins[/i], you can add custom telemetry from external devices and services to the Sideband telemetry system.\n\n"
info2 += "Restart Sideband for changes to these settings to take effect."
self.plugins_screen.ids.plugins_info1.text = info1
self.plugins_screen.ids.plugins_info2.text = info2
self.plugins_screen.ids.settings_command_plugins_enabled.active = self.sideband.config["command_plugins_enabled"]
self.plugins_screen.ids.settings_service_plugins_enabled.active = self.sideband.config["service_plugins_enabled"]
@ -3841,6 +3843,9 @@ class SidebandApp(MDApp):
self.plugins_screen.ids.settings_service_plugins_enabled.bind(active=plugins_settings_save)
def plugins_open(self, sender=None, direction="left", no_transition=False):
plugins_info_text = self.sideband.get_plugins_info()
self.plugins_screen.ids.plugins_loaded.text = plugins_info_text
if no_transition:
self.root.ids.screen_manager.transition = self.no_transition
else:

View File

@ -255,7 +255,11 @@ class SidebandCore():
self.active_service_plugins = {}
self.active_telemetry_plugins = {}
if self.is_service or self.is_standalone:
self.__load_plugins()
def load_job():
time.sleep(1)
self.__load_plugins()
threading.Thread(target=load_job, daemon=True).start()
def clear_tmp_dir(self):
if os.path.isdir(self.tmp_dir):
@ -685,6 +689,7 @@ class SidebandCore():
if plugins_enabled:
if plugins_path != None:
RNS.log("Loading Sideband plugins...", RNS.LOG_DEBUG)
if os.path.isdir(plugins_path):
for file in os.listdir(plugins_path):
if file.lower().endswith(".py"):
@ -1366,6 +1371,45 @@ class SidebandCore():
RNS.log("Error while retrieving state "+str(prop)+" over RPC: "+str(e), RNS.LOG_DEBUG)
self.rpc_connection = None
return None
def _get_plugins_info(self):
np = 0
plugins_info_text = ""
for name in self.active_service_plugins:
np += 1
plugins_info_text += f"\n- Service Plugin [b]{name}[/b]"
for name in self.active_telemetry_plugins:
np += 1
plugins_info_text += f"\n- Telemetry Plugin [b]{name}[/b]"
for name in self.active_command_plugins:
np += 1
plugins_info_text += f"\n- Command Plugin [b]{name}[/b]"
if np == 0:
plugins_info_text = "[i]No plugins are currently loaded[/i]"
elif np == 1:
plugins_info_text = "Currently, 1 plugin is loaded and active:\n" + plugins_info_text
else:
plugins_info_text = f"Currently, {np} plugins are loaded and active:\n" + plugins_info_text
return plugins_info_text
def get_plugins_info(self):
if not RNS.vendor.platformutils.is_android():
return self._get_plugins_info()
else:
if self.is_service:
return self._get_plugins_info()
else:
try:
if self.rpc_connection == None:
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
self.rpc_connection.send({"get_plugins_info": True})
response = self.rpc_connection.recv()
return response
except Exception as e:
ed = "Error while getting plugins info over RPC: "+str(e)
RNS.log(ed, RNS.LOG_DEBUG)
return ed
def __start_rpc_listener(self):
try:
@ -1404,6 +1448,10 @@ class SidebandCore():
elif "set_debug" in call:
self.service_rpc_set_debug(call["set_debug"])
connection.send(True)
elif "get_plugins_info" in call:
connection.send(self._get_plugins_info())
else:
return None
except Exception as e:
RNS.log("Error on client RPC connection: "+str(e), RNS.LOG_ERROR)

View File

@ -1162,13 +1162,19 @@ MDScreen:
height: self.minimum_height
padding: [dp(35), dp(35), dp(35), dp(35)]
MDLabel:
padding: [0,dp(0),dp(0),dp(0)]
text: "Plugin Settings"
id: plugins_active_heading
font_style: "H6"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
id: plugins_info
id: plugins_info1
markup: True
text: ""
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
MDBoxLayout:
@ -1210,6 +1216,29 @@ MDScreen:
font_size: dp(16)
size_hint: [1.0, None]
on_release: root.app.plugins_select_directory_action(self)
MDLabel:
id: plugins_info2
markup: True
text: ""
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
MDLabel:
padding: [0,dp(14),dp(0),dp(0)]
text: "Active Plugins"
id: plugins_active_heading
font_style: "H6"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
id: plugins_loaded
markup: True
text: ""
size_hint_y: None
height: self.texture_size[1]
"""
layout_settings_screen = """