mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 10:11:52 +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 io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess # nosec
|
||||||
import tempfile
|
import tempfile
|
||||||
from mss.exception import ScreenShotError
|
from mss.exception import ScreenShotError
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@ -34,7 +34,7 @@ def _capture_screen():
|
|||||||
except ScreenShotError:
|
except ScreenShotError:
|
||||||
# One common error is that mss doesn't work with Wayland
|
# One common error is that mss doesn't work with Wayland
|
||||||
if sys.platform.startswith("linux"):
|
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)
|
env = dict(os.environ)
|
||||||
lp = env.get("LD_LIBRARY_PATH_ORIG")
|
lp = env.get("LD_LIBRARY_PATH_ORIG")
|
||||||
if lp is not None:
|
if lp is not None:
|
||||||
@ -44,9 +44,18 @@ def _capture_screen():
|
|||||||
fd, fname = tempfile.mkstemp(suffix=".png")
|
fd, fname = tempfile.mkstemp(suffix=".png")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rc = subprocess.call(
|
# Try using gnome-screenshot
|
||||||
|
rc = subprocess.call( # nosec
|
||||||
["gnome-screenshot", "-f", fname], env=env
|
["gnome-screenshot", "-f", fname], env=env
|
||||||
) # nosec
|
)
|
||||||
|
if rc == 0:
|
||||||
|
return Image.open(fname)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# Try using spectacle (KDE)
|
||||||
|
try:
|
||||||
|
rc = subprocess.call( # nosec
|
||||||
|
["spectacle", "-b", "-n", "-o", fname], env=env
|
||||||
|
)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
return Image.open(fname)
|
return Image.open(fname)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
Loading…
Reference in New Issue
Block a user