Skip to content

Commit

Permalink
Add support for opening clipboard manager on Linux
Browse files Browse the repository at this point in the history
- Added support for opening clipboard manager on Linux using common clipboard managers (copyq, gpaste-client, clipman, parcellite, xfce4-clipman, klipper, diodon) or using Win+V
- Moved open clipboard logic to a dedicated open_clipboard.py file
- Updated commands.py to use the new open_clipboard function
  • Loading branch information
Lenochxd committed Dec 18, 2024
1 parent 05e929c commit f7e16b6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/buttons/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def handle_command(message=None):
pyautogui.hotkey("ctrl", "x")

elif message.startswith("/clipboard"):
pyautogui.hotkey("win", "v")
system.open_clipboard()

else:
if message.startswith(("/volume", "/soundcontrol mute")):
Expand Down
1 change: 1 addition & 0 deletions app/buttons/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from .taskkill import kill
from .restart_app import restart_app
from .clear_clipboard import clear_clipboard
from .open_clipboard import open_clipboard
from .write import handle_command as write
48 changes: 48 additions & 0 deletions app/buttons/system/open_clipboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from app.utils.platform import is_windows, is_linux

import subprocess
import pyautogui
from app.utils.logger import log


def open_clipboard():
if is_windows:
pyautogui.hotkey("win", "v")

if is_linux:
def is_command_available(command):
"""Check if a command is available on the system."""
try:
if subprocess.run(["which", command], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
return True
return False
except FileNotFoundError:
return False

# Check for common clipboard managers and open them if installed
clipboard_managers = {
"copyq": "copyq show",
"gpaste-client": "gpaste-client ui",
"clipman": "clipman show-history",
"parcellite": "parcellite",
"xfce4-clipman": "xfce4-clipman-history",
"klipper": "qdbus org.kde.klipper /klipper org.kde.klipper.klipper.showHistory",
"diodon": "diodon --indicator",
}

for manager, command in clipboard_managers.items():
if is_command_available(manager):
if subprocess.run(command, shell=True).returncode == 0:
log.success(f"Opened clipboard manager: '{manager}' Using command: '{command}'")
else:
log.error(f"Failed to open {manager}")

return

pyautogui.hotkey("win", "v")

log.error("No supported clipboard manager found. Please install one, e.g., 'copyq'. Performing default action (Win+V).")
raise RuntimeError("No supported clipboard manager found. Please install one, e.g., 'copyq'. Performing default action (Win+V).")

else:
raise NotImplementedError("This is not implemented for this platform.")

0 comments on commit f7e16b6

Please sign in to comment.