fix(services/spotlight): improve MPRIS artwork handling and scope keyword searches to single plugin
- mpris: native MediaArt cache lookup, dedupe play/pause emission, safe cleanup, artwork polling for already-playing browser players, drop os.system seek fallback - spotlight: scope plugin keyword and detect() matches to a single plugin via search_single instead of global search; register clipboard keywords (clip/clipboard)
This commit is contained in:
43 files changed
+1227
-637
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
from fabric.utils import DesktopApp, get_desktop_applications
|
||||
@@ -17,6 +18,8 @@ class ApplicationPlugin(SpotlightPlugin):
|
||||
def __init__(self, context):
|
||||
super().__init__(context)
|
||||
self._desktop_apps: list[DesktopApp] = []
|
||||
self._apps_loaded_at: float = 0.0
|
||||
self._apps_ttl: float = 1.0
|
||||
|
||||
def initialize(self) -> None:
|
||||
self._desktop_apps = get_desktop_applications()
|
||||
@@ -28,6 +31,16 @@ class ApplicationPlugin(SpotlightPlugin):
|
||||
if not query:
|
||||
return []
|
||||
|
||||
# Re-scan (throttled) so newly installed .desktop files appear
|
||||
# without a restart, while avoiding a disk scan on every keystroke.
|
||||
now = time.monotonic()
|
||||
if now - self._apps_loaded_at > self._apps_ttl:
|
||||
try:
|
||||
self._desktop_apps = get_desktop_applications()
|
||||
self._apps_loaded_at = now
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
results: list[SearchResult] = []
|
||||
for app in self._desktop_apps:
|
||||
display_name = getattr(app, "display_name", "") or ""
|
||||
@@ -60,7 +73,9 @@ class ApplicationPlugin(SpotlightPlugin):
|
||||
|
||||
@staticmethod
|
||||
def _launch_app(app: DesktopApp) -> None:
|
||||
app.launch()
|
||||
from globalmenu.launch import launch_desktop_app
|
||||
|
||||
launch_desktop_app(app)
|
||||
|
||||
|
||||
PLUGIN = ApplicationPlugin
|
||||
@@ -13,6 +13,7 @@ class ClipboardPlugin(SpotlightPlugin):
|
||||
id = "clipboard"
|
||||
name = "Clipboard"
|
||||
icon = "edit-paste-symbolic"
|
||||
keywords = ["clip", "clipboard"]
|
||||
searchable = True
|
||||
priority = 80
|
||||
|
||||
@@ -45,7 +46,11 @@ class ClipboardPlugin(SpotlightPlugin):
|
||||
|
||||
def search(self, query: str, token: Any) -> list[SearchResult]:
|
||||
q = query.strip()
|
||||
if q.lower().startswith("clip "):
|
||||
if q.lower().startswith("clipboard "):
|
||||
q = q[10:].strip()
|
||||
elif q.lower() == "clipboard":
|
||||
q = ""
|
||||
elif q.lower().startswith("clip "):
|
||||
q = q[5:].strip()
|
||||
elif q.lower() == "clip":
|
||||
q = ""
|
||||
|
||||
@@ -36,7 +36,6 @@ class EmojiPlugin(SpotlightPlugin):
|
||||
return
|
||||
cldr = self._load_cldr_annotations()
|
||||
self._emoji_data = cldr or {}
|
||||
logger.info(f"[Emoji] Loaded {len(self._emoji_data)} emojis")
|
||||
|
||||
def detect(self, text: str) -> bool:
|
||||
s = text.strip()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import gc
|
||||
import os
|
||||
import random
|
||||
from typing import Any
|
||||
@@ -8,7 +7,7 @@ from shared.data import WALLPAPERS_THUMBNAILS_SIZE
|
||||
from utils.functions import fuzzy_filter
|
||||
from window.spotlight.api import SearchResult, SpotlightPlugin
|
||||
|
||||
MAX_THUMBS_PER_SEARCH = 5
|
||||
MAX_THUMBS_PER_SEARCH = 3
|
||||
|
||||
|
||||
class WallpaperPlugin(SpotlightPlugin):
|
||||
@@ -28,7 +27,6 @@ class WallpaperPlugin(SpotlightPlugin):
|
||||
|
||||
def cleanup(self) -> None:
|
||||
self._wallpaper_service = None
|
||||
gc.collect()
|
||||
|
||||
def release_memory(self) -> None:
|
||||
if self._wallpaper_service:
|
||||
|
||||
Reference in new issue
Block a user