mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 02:01:36 +03:00
Add screenshot fallback using spectacle.
This commit is contained in:
parent
6c2c17b3a2
commit
14ca9f0f13
@ -18,7 +18,7 @@ import base64
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import subprocess # nosec
|
||||
import tempfile
|
||||
from mss.exception import ScreenShotError
|
||||
from PIL import Image
|
||||
@ -34,7 +34,7 @@ def _capture_screen():
|
||||
except ScreenShotError:
|
||||
# One common error is that mss doesn't work with Wayland
|
||||
if sys.platform.startswith("linux"):
|
||||
# Try gnome-screenshot fallback, with original library path
|
||||
# Try calling screenshot tools, with original library path
|
||||
env = dict(os.environ)
|
||||
lp = env.get("LD_LIBRARY_PATH_ORIG")
|
||||
if lp is not None:
|
||||
@ -44,13 +44,22 @@ def _capture_screen():
|
||||
fd, fname = tempfile.mkstemp(suffix=".png")
|
||||
|
||||
try:
|
||||
rc = subprocess.call(
|
||||
# Try using gnome-screenshot
|
||||
rc = subprocess.call( # nosec
|
||||
["gnome-screenshot", "-f", fname], env=env
|
||||
) # nosec
|
||||
)
|
||||
if rc == 0:
|
||||
return Image.open(fname)
|
||||
except FileNotFoundError:
|
||||
pass # Fall through to ValueError
|
||||
# Try using spectacle (KDE)
|
||||
try:
|
||||
rc = subprocess.call( # nosec
|
||||
["spectacle", "-b", "-n", "-o", fname], env=env
|
||||
)
|
||||
if rc == 0:
|
||||
return Image.open(fname)
|
||||
except FileNotFoundError:
|
||||
pass # Fall through to ValueError
|
||||
finally:
|
||||
os.unlink(fname)
|
||||
raise ValueError("Unable to capture screenshot")
|
||||
|
Loading…
Reference in New Issue
Block a user