mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
use gnome shell screenshot dbus api
This commit is contained in:
parent
8545628e9b
commit
aa54801231
8 changed files with 40 additions and 42 deletions
|
@ -17,4 +17,4 @@
|
|||
along with Authenticator. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from .application import Application
|
||||
from .utils import is_gnome, screenshot_area
|
||||
from .utils import is_gnome
|
||||
|
|
|
@ -24,3 +24,4 @@ from .account import Account
|
|||
from .logger import Logger
|
||||
from .keyring import Keyring
|
||||
from .clipboard import Clipboard
|
||||
from .screenshot import GNOMEScreenshot
|
||||
|
|
|
@ -42,7 +42,7 @@ class QRReader:
|
|||
query_params = parse_qsl(url.query)
|
||||
self._codes = dict(query_params)
|
||||
return self._codes.get("secret")
|
||||
except KeyError:
|
||||
except (KeyError, IndexError):
|
||||
Logger.error("Invalid QR image")
|
||||
return None
|
||||
|
||||
|
|
30
Authenticator/models/screenshot.py
Normal file
30
Authenticator/models/screenshot.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import dbus
|
||||
from os import path
|
||||
from tempfile import NamedTemporaryFile, gettempdir
|
||||
|
||||
class GNOMEScreenshot:
|
||||
|
||||
interface = "org.gnome.Shell.Screenshot"
|
||||
|
||||
@staticmethod
|
||||
def area(filename=None):
|
||||
if not filename:
|
||||
filename = path.join(gettempdir(), NamedTemporaryFile().name)
|
||||
bus = dbus.SessionBus()
|
||||
shell_obj = bus.get_object(GNOMEScreenshot.interface,
|
||||
"/org/gnome/Shell/Screenshot")
|
||||
screen_intf = dbus.Interface(shell_obj, GNOMEScreenshot.interface)
|
||||
|
||||
area = screen_intf.SelectArea()
|
||||
x = dbus.Int64(area[0])
|
||||
y = dbus.Int64(area[1])
|
||||
width = dbus.Int64(area[2])
|
||||
height = dbus.Int64(area[3])
|
||||
|
||||
screenshot = screen_intf.ScreenshotArea(x, y, width, height,
|
||||
False, filename)
|
||||
success = dbus.Boolean(screenshot[0])
|
||||
if success:
|
||||
filename = dbus.String(screenshot[1])
|
||||
return filename
|
||||
return None
|
|
@ -19,7 +19,6 @@
|
|||
from os import path, environ
|
||||
import logging
|
||||
from subprocess import PIPE, Popen, call
|
||||
from tempfile import NamedTemporaryFile, gettempdir
|
||||
|
||||
|
||||
def is_gnome():
|
||||
|
@ -27,26 +26,3 @@ def is_gnome():
|
|||
Check if the current distro is gnome
|
||||
"""
|
||||
return environ.get("XDG_CURRENT_DESKTOP").lower() == "gnome"
|
||||
|
||||
|
||||
def screenshot_area():
|
||||
"""
|
||||
Screenshot an area of the screen using gnome-screenshot
|
||||
used to QR scan
|
||||
"""
|
||||
ink_flag = call(['which', 'gnome-screenshot'], stdout=PIPE, stderr=PIPE)
|
||||
if ink_flag == 0:
|
||||
file_name = path.join(gettempdir(), NamedTemporaryFile().name)
|
||||
_, error = Popen(["gnome-screenshot", "-a", "-f", file_name],
|
||||
stdout=PIPE, stderr=PIPE).communicate()
|
||||
if error:
|
||||
error = error.decode("utf-8").split("\n")
|
||||
logging.error("\n".join([e for e in error]))
|
||||
if not path.isfile(file_name):
|
||||
logging.debug("The screenshot was not taken")
|
||||
return None
|
||||
return file_name
|
||||
else:
|
||||
logging.error("Couldn't find gnome-screenshot"
|
||||
", please install it first")
|
||||
return None
|
||||
|
|
|
@ -26,8 +26,7 @@ from gi.repository import Gio, Gtk, GObject
|
|||
from ..headerbar import HeaderBarButton, HeaderBarToggleButton
|
||||
from ..inapp_notification import InAppNotification
|
||||
from ..search_bar import SearchBar
|
||||
from ...models import Code, QRReader
|
||||
from ...utils import screenshot_area
|
||||
from ...models import Code, QRReader, GNOMEScreenshot
|
||||
|
||||
|
||||
class AddAcountWindow(Gtk.Window):
|
||||
|
@ -294,9 +293,9 @@ class AccountConfig(Gtk.Box, GObject.GObject):
|
|||
Gtk.IconSize.DIALOG)
|
||||
|
||||
def scan_qr(self):
|
||||
screenshot_file = screenshot_area()
|
||||
if screenshot_file:
|
||||
qr_reader = QRReader(screenshot_file)
|
||||
filename = GNOMEScreenshot.area()
|
||||
if filename:
|
||||
qr_reader = QRReader(filename)
|
||||
secret = qr_reader.read()
|
||||
if not qr_reader.is_valid():
|
||||
self.notification.set_message(_("Invalid QR code"))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Authenticator
|
||||
<img src="https://raw.githubusercontent.com/bilelmoussaoui/Authenticator/master/data/icons/hicolor/256x256/apps/com.github.bilelmoussaoui.Authenticator.png" width="128" height="128" />
|
||||
<p>Two-factor authentication code generator for Gnome. Created with love using Python and Gtk.</p>
|
||||
<p>Two-factor authentication code generator for GNOME. Created with love using Python and Gtk.</p>
|
||||
|
||||
## Screenshots
|
||||
|
||||
|
@ -36,7 +36,6 @@ flatpak install flathub com.github.bilelmoussaoui.Authenticator
|
|||
- `libzbar-dev` on Ubuntu
|
||||
- `zbar` on Arch
|
||||
- `libsecret`
|
||||
- `gnome-screenshot`
|
||||
|
||||
1 - Clone the repository
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
"--socket=wayland",
|
||||
/* Keyring */
|
||||
"--talk-name=org.freedesktop.secrets",
|
||||
/* Screenshot (used to scan QR code)*/
|
||||
"--talk-name=org.gnome.Shell.Screenshot",
|
||||
/* dconf */
|
||||
"--filesystem=xdg-run/dconf", "--filesystem=~/.config/dconf:ro",
|
||||
"--talk-name=ca.desrt.dconf", "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
|
||||
|
@ -126,15 +128,6 @@
|
|||
"sha256": "7387899656e4e9564b7e507b2c26729c4863b7a79bbaf29c80c956a5654d2ee0"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "gnome-screenshot",
|
||||
"buildsystem": "meson",
|
||||
"sources": [{
|
||||
"type": "archive",
|
||||
"url": "https://github.com/GNOME/gnome-screenshot/archive/3.26.0.tar.gz",
|
||||
"sha256": "7bb1462b4b14db574e270d5dddbcd4ec8bf2f5f45681c729b66ecdabae4abad4"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "Authenticator",
|
||||
"buildsystem": "meson",
|
||||
|
|
Loading…
Add table
Reference in a new issue