mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-02 02:42:04 +00:00
docs: clarify manual clipboard dependencies
This commit is contained in:
1 parent
36061493ac
commit
ccca399b09
11 files changed
+166
-139
No files matched your search
+26
-19
@@ -1,8 +1,7 @@
|
||||
import threading
|
||||
import logging
|
||||
import subprocess
|
||||
import shutil
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import pyperclip
|
||||
|
||||
@@ -10,31 +9,38 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _ensure_clipboard() -> None:
|
||||
"""Attempt to ensure a clipboard mechanism is available."""
|
||||
"""Ensure a clipboard mechanism is available or raise an informative error."""
|
||||
try:
|
||||
pyperclip.copy("")
|
||||
except pyperclip.PyperclipException as exc:
|
||||
if sys.platform.startswith("linux"):
|
||||
if shutil.which("xclip") is None and shutil.which("xsel") is None:
|
||||
apt = shutil.which("apt-get") or shutil.which("apt")
|
||||
if apt:
|
||||
try:
|
||||
subprocess.run(
|
||||
["sudo", apt, "install", "-y", "xclip"], check=True
|
||||
)
|
||||
pyperclip.copy("")
|
||||
return
|
||||
except Exception as install_exc: # pragma: no cover - system dep
|
||||
logger.warning(
|
||||
"Automatic xclip installation failed: %s", install_exc
|
||||
)
|
||||
raise exc
|
||||
raise pyperclip.PyperclipException(
|
||||
"Clipboard support requires the 'xclip' package. "
|
||||
"Install it with 'sudo apt install xclip' and restart SeedPass."
|
||||
) from exc
|
||||
raise
|
||||
|
||||
|
||||
def copy_to_clipboard(text: str, timeout: int) -> None:
|
||||
"""Copy text to the clipboard and clear after timeout seconds if unchanged."""
|
||||
def copy_to_clipboard(text: str, timeout: int) -> bool:
|
||||
"""Copy text to the clipboard and clear after timeout seconds if unchanged.
|
||||
|
||||
Returns True if the text was successfully copied, False otherwise.
|
||||
"""
|
||||
|
||||
try:
|
||||
_ensure_clipboard()
|
||||
except pyperclip.PyperclipException as exc:
|
||||
warning = (
|
||||
"Clipboard unavailable: "
|
||||
+ str(exc)
|
||||
+ "\nSeedPass secret mode requires clipboard support. "
|
||||
"Install xclip or disable secret mode to view secrets."
|
||||
)
|
||||
logger.warning(warning)
|
||||
print(warning)
|
||||
return False
|
||||
|
||||
_ensure_clipboard()
|
||||
pyperclip.copy(text)
|
||||
|
||||
def clear_clipboard() -> None:
|
||||
@@ -44,3 +50,4 @@ def copy_to_clipboard(text: str, timeout: int) -> None:
|
||||
timer = threading.Timer(timeout, clear_clipboard)
|
||||
timer.daemon = True
|
||||
timer.start()
|
||||
return True
|
||||
Reference in new issue
Block a user