This commit is contained in:
sankalp committed 2025-07-21 00:55:51 +05:45
1 parent 532d3ceb39
commit 4a2fc70ff9
4 files changed
+70 -60

No files matched your search

+20 -10
View File
@@ -27,7 +27,8 @@ class ClipboardPlugin(PluginBase):
# Initialize cache and temp directory
self.tmp_dir = tempfile.mkdtemp(prefix="cliphist-")
self.image_cache: Dict[str, GdkPixbuf.Pixbuf] = {} # Cache images forever like example_cliphist.py
# Cache images forever like example_cliphist.py
self.image_cache: Dict[str, GdkPixbuf.Pixbuf] = {}
self.clipboard_items_cache: List[str] = []
self.cache_timestamp = 0
@@ -212,11 +213,14 @@ class ClipboardPlugin(PluginBase):
def _is_image_data(self, content: str) -> bool:
"""Determine if clipboard content is likely an image (like example_cliphist.py)."""
return (
content.startswith("data:image/") or
content.startswith("\x89PNG") or
content.startswith("GIF8") or
content.startswith("\xff\xd8\xff") or
"binary" in content.lower() and any(ext in content.lower() for ext in ["jpg", "jpeg", "png", "bmp", "gif"])
content.startswith("data:image/")
or content.startswith("\x89PNG")
or content.startswith("GIF8")
or content.startswith("\xff\xd8\xff")
or "binary" in content.lower()
and any(
ext in content.lower() for ext in ["jpg", "jpeg", "png", "bmp", "gif"]
)
)
def _get_text_preview(self, content: str) -> str:
@@ -288,13 +292,15 @@ class ClipboardPlugin(PluginBase):
elif query_lower in content_lower:
# Position-based scoring: earlier matches get higher scores
position = content_lower.find(query_lower)
relevance = max(0.5, 1.0 - (position / len(content_lower)) * 0.4)
relevance = max(
0.5, 1.0 - (position / len(content_lower)) * 0.4
)
filtered_items.append((item, relevance))
# Sort by relevance (highest first) and then limit results
filtered_items.sort(key=lambda x: x[1], reverse=True)
filtered_items = filtered_items[:self.max_results]
filtered_items = filtered_items[: self.max_results]
# Process items with lazy image loading
for i, (item, relevance) in enumerate(filtered_items):
@@ -334,7 +340,9 @@ class ClipboardPlugin(PluginBase):
icon=immediate_pixbuf,
relevance=relevance,
plugin_name=self.name,
action=lambda id=item_id: self._copy_to_clipboard(id),
action=lambda id=item_id: self._copy_to_clipboard(
id
),
data={"bypass_max_results": True},
)
else:
@@ -346,7 +354,9 @@ class ClipboardPlugin(PluginBase):
icon_name="image-x-generic",
relevance=relevance,
plugin_name=self.name,
action=lambda id=item_id: self._copy_to_clipboard(id),
action=lambda id=item_id: self._copy_to_clipboard(
id
),
data={"bypass_max_results": True},
)
except Exception:
+11 -10
View File
@@ -115,7 +115,6 @@ class ScreencapturePlugin(PluginBase):
def _get_command_result(self, command: str) -> Result:
"""Get a Result object for a specific command."""
# Import here to avoid circular imports
from utils.icons import screenrecord, screenshots, ssfull, ssregion, stop
command_info = {
# Screenshot commands
@@ -436,7 +435,6 @@ class ScreencapturePlugin(PluginBase):
def query(self, query_string: str) -> List[Result]:
"""Search for screencapture actions based on query."""
# Import here to avoid circular imports
from utils.icons import screenrecord, screenshots, ssfull, ssregion, stop
# Clean the query string
query = query_string.strip().lower()
@@ -463,14 +461,17 @@ class ScreencapturePlugin(PluginBase):
if command in file_conversion_commands:
format_type = file_conversion_commands[command]
return [Result(
title=f"Convert {file_param} to {format_type.upper()}",
subtitle=f"Convert specified file to {format_type} format",
icon_markup=screenrecord,
action=lambda fp=file_param, ft=format_type: self._run_script_with_file(ft, fp),
relevance=1.0,
plugin_name=self.display_name,
)]
return [
Result(
title=f"Convert {file_param} to {format_type.upper()}",
subtitle=f"Convert specified file to {format_type} format",
icon_markup=screenrecord,
action=lambda fp=file_param,
ft=format_type: self._run_script_with_file(ft, fp),
relevance=1.0,
plugin_name=self.display_name,
)
]
# Check if query matches a command and return it as a result
command_result = self._get_command_result(query)