mainly whitespace, but also some generic qol improvements
This commit is contained in:
1 parent
2a5e3f5606
commit
3a8ffbdf70
26 files changed
+1871
-1224
No files matched your search
+99
-4
@@ -22,7 +22,7 @@ from typing import Any, cast
|
||||
|
||||
# External library imports
|
||||
import certifi
|
||||
from PySide6.QtCore import QObject, QUrl, Signal
|
||||
from PySide6.QtCore import QObject, QThread, QUrl, Signal
|
||||
from PySide6.QtGui import QDesktopServices
|
||||
from PySide6.QtWidgets import QMainWindow, QMenu, QMessageBox
|
||||
|
||||
@@ -58,7 +58,7 @@ def parse_version(v_str: str) -> tuple[int, ...]:
|
||||
|
||||
class PluginManager(QObject):
|
||||
"""
|
||||
Handles plugin discovery, dynamic loading, menu building,
|
||||
Handles plugin discovery, dynamic loading, menu building,
|
||||
and plugin lifecycle (install, toggle, uninstall).
|
||||
"""
|
||||
|
||||
@@ -227,7 +227,7 @@ class PluginManager(QObject):
|
||||
# Load local plugin.json if present
|
||||
manifest: dict[str, Any] = {}
|
||||
manifest_path = (entry / "plugin.json") if entry.is_dir() else None
|
||||
|
||||
|
||||
if manifest_path and manifest_path.exists():
|
||||
try:
|
||||
with open(manifest_path, "r", encoding="utf-8") as f:
|
||||
@@ -328,4 +328,99 @@ class PluginManager(QObject):
|
||||
"""Opens the local plugins folder in the operating system's file manager."""
|
||||
if self.plugins_dir.exists():
|
||||
return QDesktopServices.openUrl(QUrl.fromLocalFile(str(self.plugins_dir)))
|
||||
return False
|
||||
return False
|
||||
|
||||
def check_for_updates(self, repo_urls: list[str]) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Fetches remote repositories and compares server plugin versions
|
||||
against installed plugins, returning the installed plugins list
|
||||
enriched with update metadata.
|
||||
"""
|
||||
installed_plugins = self.get_installed_plugins_info()
|
||||
remote_data, _ = self.fetch_remote_repositories(repo_urls)
|
||||
|
||||
# Index remote plugins by their ID (fallback to name if id is missing)
|
||||
remote_map: dict[str, dict[str, Any]] = {}
|
||||
for remote_plugin in remote_data:
|
||||
plugin_id = remote_plugin.get("id") or remote_plugin.get("name")
|
||||
if plugin_id:
|
||||
remote_map[str(plugin_id)] = remote_plugin
|
||||
|
||||
# Compare versions and annotate each installed plugin dictionary
|
||||
for plugin in installed_plugins:
|
||||
plugin_id = str(plugin.get("id", ""))
|
||||
local_version_str = str(plugin.get("version", "0.0.0"))
|
||||
local_tuple = parse_version(local_version_str)
|
||||
|
||||
remote_plugin = remote_map.get(plugin_id)
|
||||
if remote_plugin:
|
||||
remote_version_str = str(remote_plugin.get("version", "0.0.0"))
|
||||
remote_tuple = parse_version(remote_version_str)
|
||||
|
||||
if remote_tuple > local_tuple:
|
||||
plugin["update_available"] = True
|
||||
plugin["remote_version"] = remote_version_str
|
||||
plugin["download_url"] = str(remote_plugin.get("download_url", ""))
|
||||
else:
|
||||
plugin["update_available"] = False
|
||||
plugin["remote_version"] = remote_version_str
|
||||
plugin["download_url"] = ""
|
||||
else:
|
||||
plugin["update_available"] = False
|
||||
plugin["remote_version"] = None
|
||||
plugin["download_url"] = ""
|
||||
|
||||
return installed_plugins
|
||||
|
||||
|
||||
class StartupUpdateWorker(QThread):
|
||||
updates_checked = Signal(list)
|
||||
|
||||
def __init__(self, manager: Any, repo_urls: list[str]) -> None:
|
||||
super().__init__()
|
||||
self.manager = manager
|
||||
self.repo_urls = repo_urls
|
||||
|
||||
def run(self) -> None:
|
||||
try:
|
||||
print("[StartupWorker] Starting background update check...")
|
||||
installed_plugins = self.manager.get_installed_plugins_info()
|
||||
print(f"[StartupWorker] Found {len(installed_plugins)} installed local plugins.")
|
||||
|
||||
remote_data, all_failed = self.manager.fetch_remote_repositories(self.repo_urls)
|
||||
print(f"[StartupWorker] Fetch remote complete. Failed: {all_failed}, Items fetched: {len(remote_data)}")
|
||||
|
||||
if all_failed or not remote_data:
|
||||
print("[StartupWorker] Aborting: Remote fetch failed or returned empty data.")
|
||||
return
|
||||
|
||||
remote_map: dict[str, dict[str, Any]] = {}
|
||||
for raw_plugin in remote_data:
|
||||
if isinstance(raw_plugin, dict):
|
||||
remote_plugin = cast(dict[str, Any], raw_plugin)
|
||||
|
||||
plugin_id = remote_plugin.get("id") or remote_plugin.get("name")
|
||||
if isinstance(plugin_id, str):
|
||||
remote_map[plugin_id] = remote_plugin
|
||||
|
||||
outdated_plugins: list[dict[str, Any]] = []
|
||||
for plugin in installed_plugins:
|
||||
plugin_id = str(plugin.get("id", ""))
|
||||
local_version_str = str(plugin.get("version", "0.0.0"))
|
||||
local_tuple = parse_version(local_version_str)
|
||||
|
||||
remote_plugin = remote_map.get(plugin_id)
|
||||
if remote_plugin:
|
||||
remote_version_str = str(remote_plugin.get("version", "0.0.0"))
|
||||
remote_tuple = parse_version(remote_version_str)
|
||||
print(f"[StartupWorker] Comparing '{plugin.get('name')}': Local v{local_version_str} vs Remote v{remote_version_str}")
|
||||
|
||||
if remote_tuple > local_tuple:
|
||||
plugin["remote_version"] = remote_version_str
|
||||
plugin["download_url"] = str(remote_plugin.get("download_url", ""))
|
||||
outdated_plugins.append(plugin)
|
||||
|
||||
print(f"[StartupWorker] Outdated plugins found: {len(outdated_plugins)}")
|
||||
self.updates_checked.emit(outdated_plugins)
|
||||
except Exception as e:
|
||||
print(f"[StartupWorker] Error during startup update check: {e}")
|
||||
Reference in new issue
Block a user