diff --git a/generator-manifest.json b/generator-manifest.json index 7ac314d..62f6afe 100644 --- a/generator-manifest.json +++ b/generator-manifest.json @@ -10,7 +10,7 @@ "package_name": "enigma2-plugin-systemplugins-remotesupport", "plugin_src_rel": "RemoteSupport", "python_package": "RemoteSupport", - "rdepends_recipe": "sshx python3-cbor2 python3-cryptography python3-pyte python3-qrcode python3-websocket-client", + "rdepends_recipe": "sshx python3-cbor2 python3-cryptography python3-pyte python3-websocket-client", "replaces": "", "repo_name": "RemoteSupport", "rrecommends": "", diff --git a/src/RemoteSupport/RemoteSupport.py b/src/RemoteSupport/RemoteSupport.py index cc1cbda..0dab4b7 100644 --- a/src/RemoteSupport/RemoteSupport.py +++ b/src/RemoteSupport/RemoteSupport.py @@ -669,17 +669,6 @@ def shareUrl(link): # The page to send the link from the phone. The link is in return f"{SHARE_PAGE}#{enigmaLanguage()},{distro},{receiver},{link}" -def printQrCode(text): - try: - from qrcode import QRCode, constants # Not at module level as the package may be missing. - qrCode = QRCode(error_correction=constants.ERROR_CORRECT_L, border=1) # Small for the terminal, a screen needs no more error correction. - qrCode.add_data(text) - qrCode.make(fit=True) - qrCode.print_ascii(out=stdout, invert=True) - except ImportError: - pass - - def watcherModules(): try: return all(find_spec(module) for module in WATCHER_MODULES) @@ -796,10 +785,10 @@ def attach(self): self.sessionLog = readFile(LOG_PATH_FILE) link = readFile(LINK_FILE) share = shareUrl(link) - print(f"\nSend this link to your supporter or scan the QR code with your phone and send it from there:\n\n{link}\n") - printQrCode(share) - print(f"QR: {share}") # Tools that start remotesupport show the QR code of this line. - print("\nDo not post the link or a screenshot of it in public forums: everybody who has it can try to join.\n") + print(f"\nSend this link to your supporter:\n\n{link}\n") + if not stdout.isatty() or environ.get("TERM") == "dumb": + print(f"QR: {share}\n") # Tools that start remotesupport show the QR code of this line. + print("Do not post the link or a screenshot of it in public forums: everybody who has it can try to join.\n") if enigmaRunning(): print("enigma2 manages the session, the access is approved on the TV. 'remotesupport stop' ends it.") return 0 diff --git a/src/RemoteSupport/plugin.py b/src/RemoteSupport/plugin.py index 20c601d..46c6dd5 100644 --- a/src/RemoteSupport/plugin.py +++ b/src/RemoteSupport/plugin.py @@ -12,7 +12,7 @@ from socket import AF_UNIX, SOCK_DGRAM, gethostname, socket from time import strftime, strptime, time -from enigma import RT_HALIGN_LEFT, RT_VALIGN_CENTER, RT_VALIGN_TOP, eCanvas, eListbox, eListboxPythonMultiContent, eRect, eSocketNotifier, eTimer, gFont, gRGB, getDesktop +from enigma import RT_HALIGN_LEFT, RT_VALIGN_CENTER, RT_VALIGN_TOP, eListbox, eListboxPythonMultiContent, eSocketNotifier, eTimer, gFont, getDesktop from Components.ActionMap import HelpableActionMap from Components.config import config @@ -22,6 +22,7 @@ from Components.MenuList import MenuList from Components.MultiContent import MultiContentEntryRectangle, MultiContentEntryText from Components.Pixmap import MultiPixmap +from Components.QRCode import QRCode from Components.Sources.StaticText import StaticText from Components.SystemInfo import BoxInfo from Plugins.Plugin import PluginDescriptor @@ -40,7 +41,7 @@ MODULE_NAME = "RemoteSupport" -REQUIRED_MODULES = ("websocket", "cbor2", "cryptography.hazmat.primitives.kdf.argon2", "qrcode", "pyte") +REQUIRED_MODULES = ("websocket", "cbor2", "cryptography.hazmat.primitives.kdf.argon2", "pyte") USERS = (" Users: ", " Participants: ") # The latter in logs of older versions. APPROVAL_QUESTION_TIMEOUT = 30 HANDOVER_APPROVAL_WINDOW = 30 # Who is connected this long after taking over a session with approved terminals keeps the access. @@ -561,54 +562,6 @@ def sessionStart(reason, session=None, **kwargs): addExternalChild(("remotesupport", RemoteSupportWeb(), title(), "1", True, "_self")) # Shown in the content area. -class QRCodeWidget(GUIComponent): - GUI_WIDGET = eCanvas - - def __init__(self): - GUIComponent.__init__(self) - self.text = None - - def postWidgetCreate(self, instance): - self.hide() - - def setText(self, text): - if text != self.text: - self.text = text - self.draw() - - def draw(self): - if self.instance is None: - return - if not self.text: - self.hide() - return - from qrcode import QRCode, constants # Not at module level as the package may be missing. - qrCode = QRCode(error_correction=constants.ERROR_CORRECT_M, border=0) - qrCode.add_data(self.text) - qrCode.make(fit=True) - matrix = qrCode.get_matrix() - size = self.instance.size() - self.instance.setSize(size) # Allocates the canvas pixmap. - width, height = size.width(), size.height() - modules = len(matrix) + 8 # Quiet zone of 4 modules on each side. - scale = min(width, height) // modules - offsetX = (width - scale * len(matrix)) // 2 - offsetY = (height - scale * len(matrix)) // 2 - self.instance.fillRect(eRect(0, 0, width, height), gRGB(0x00FFFFFF)) - black = gRGB(0x00000000) - for y, row in enumerate(matrix): - x = 0 - while x < len(row): - if row[x]: - start = x - while x < len(row) and row[x]: - x += 1 - self.instance.fillRect(eRect(offsetX + start * scale, offsetY + y * scale, (x - start) * scale, scale), black) - else: - x += 1 - self.show() - - def consoleFontSize(width, height, columns, lines): # The largest monospaced font that fits the terminal into the area. return max(4, min(int(height / lines / LINE_HEIGHT_RATIO), int(width / columns / FONT_WIDTH_RATIO))) @@ -739,7 +692,7 @@ def __init__(self, session): self["counts"] = Label() self["url"] = Label() self["linkwarning"] = Label() - self["qrcode"] = QRCodeWidget() + self["qrcode"] = QRCode() self["qrhint"] = Label() self["key_red"] = StaticText(_("Close")) self["key_green"] = StaticText() diff --git a/src/RemoteSupport/web.py b/src/RemoteSupport/web.py index 406b394..e8b6ca0 100644 --- a/src/RemoteSupport/web.py +++ b/src/RemoteSupport/web.py @@ -2,9 +2,10 @@ from json import dumps from os.path import basename - from twisted.web import resource +from enigma import eQRCode + from . import _ from .plugin import IDLE_WARNING, SshxSession, deleteSessionLogs, incomplete, participants, sessionGrabs, sessionLogs, sshxSession @@ -429,12 +430,8 @@ def download(self, request, name): # Only the listed session logs and their gra def qrCode(self, url): if url and url != self.qrUrl: - from qrcode import QRCode, constants # Not at module level as the package may be missing. - qrCode = QRCode(error_correction=constants.ERROR_CORRECT_M, border=0) - qrCode.add_data(url) - qrCode.make(fit=True) self.qrUrl = url - self.qrMatrix = ["".join("1" if module else "0" for module in row) for row in qrCode.get_matrix()] + self.qrMatrix = eQRCode.getModules(url, eQRCode.ecMedium).split("\n") return self.qrMatrix if url else [] def texts(self):