|
5 | 5 | import psutil |
6 | 6 | import platform |
7 | 7 | import subprocess |
| 8 | +import importlib.util |
| 9 | + |
8 | 10 | from PyQt5.QtCore import Qt, QThread, pyqtSignal |
9 | 11 | from PyQt5.QtGui import QFont |
10 | 12 | from PyQt5.QtWidgets import ( |
|
17 | 19 |
|
18 | 20 |
|
19 | 21 |
|
| 22 | +""" Utility function to load plugins """ |
| 23 | +def load_plugins(app_context): |
| 24 | + user_home = os.path.expanduser("~") |
| 25 | + plugins_dir = os.path.join(user_home, "rmplugins") |
| 26 | + os.makedirs(plugins_dir, exist_ok=True) |
| 27 | + loaded_plugins = [] |
| 28 | + for filename in os.listdir(plugins_dir): |
| 29 | + if filename.endswith(".py") and not filename.startswith("_"): |
| 30 | + plugin_path = os.path.join(plugins_dir, filename) |
| 31 | + mod_name = os.path.splitext(filename)[0] |
| 32 | + spec = importlib.util.spec_from_file_location(mod_name, plugin_path) |
| 33 | + module = importlib.util.module_from_spec(spec) |
| 34 | + try: |
| 35 | + spec.loader.exec_module(module) |
| 36 | + if hasattr(module, "register_plugin"): |
| 37 | + module.register_plugin(app_context) |
| 38 | + loaded_plugins.append(mod_name) |
| 39 | + print(f"Plugin '{mod_name}' loaded successfully from {plugins_dir}") |
| 40 | + except Exception as e: |
| 41 | + print(f"Failed to load plugin '{filename}' from {plugins_dir}: {e}") |
| 42 | + return loaded_plugins |
| 43 | + |
| 44 | + |
| 45 | + |
20 | 46 | """ Function to load the CSS style for the program """ |
21 | 47 | def loadStyle(): |
22 | 48 | user_css_path = os.path.join(os.path.expanduser("~"), "rmstyle.css") |
@@ -147,6 +173,8 @@ def __init__(self): |
147 | 173 | self.fetcher.update_drives.connect(self.update_drives) |
148 | 174 | self.fetcher.update_stats.connect(self.update_stats) |
149 | 175 | self.fetcher.start() |
| 176 | + app_context = {"main_window": self} |
| 177 | + self.plugins = load_plugins(app_context) |
150 | 178 |
|
151 | 179 | def init_ui(self): |
152 | 180 | loadStyle() |
|
0 commit comments