Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 8896ad2

Browse files
author
Raven
committed
Added Plugin Support
1 parent ba504ba commit 8896ad2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

resmon.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import psutil
66
import platform
77
import subprocess
8+
import importlib.util
9+
810
from PyQt5.QtCore import Qt, QThread, pyqtSignal
911
from PyQt5.QtGui import QFont
1012
from PyQt5.QtWidgets import (
@@ -17,6 +19,30 @@
1719

1820

1921

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+
2046
""" Function to load the CSS style for the program """
2147
def loadStyle():
2248
user_css_path = os.path.join(os.path.expanduser("~"), "rmstyle.css")
@@ -147,6 +173,8 @@ def __init__(self):
147173
self.fetcher.update_drives.connect(self.update_drives)
148174
self.fetcher.update_stats.connect(self.update_stats)
149175
self.fetcher.start()
176+
app_context = {"main_window": self}
177+
self.plugins = load_plugins(app_context)
150178

151179
def init_ui(self):
152180
loadStyle()

0 commit comments

Comments
 (0)