Merge pull request #1 from radarhere/grabclipboard

Rearranged code
This commit is contained in:
Nicola Guerrera 2024-01-27 11:04:43 +01:00 committed by GitHub
commit 1522b3fb84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -157,17 +157,21 @@ def grabclipboard():
raise NotImplementedError(msg)
p = subprocess.run(args, capture_output=True)
err = p.stderr.decode()
if p.returncode != 0:
allowed_errors = [
"Nothing is copied", # wl-paste, when the clipboard is empty
"not available", # wl-paste/debian xclip, when an image isn't available
"cannot convert", # xclip, when an image isn't available
"There is no owner", # xclip, when the clipboard isn't initialized
# wl-paste, when the clipboard is empty
b"Nothing is copied",
# wl-paste/debian xclip, when an image isn't available
b"not available",
# xclip, when an image isn't available
b"cannot convert",
# xclip, when the clipboard isn't initialized
b"There is no owner",
]
err = p.stderr
if any(e in err for e in allowed_errors):
return None
msg = f"{args[0]} error: {err.strip() if err else 'Unknown error'}"
msg = f"{args[0]} error: {err.strip().decode() if err else 'Unknown error'}"
raise ChildProcessError(msg)
data = io.BytesIO(p.stdout)