diff --git a/server/build_binary.py b/server/build_binary.py index c7b9662..0240a58 100755 --- a/server/build_binary.py +++ b/server/build_binary.py @@ -29,10 +29,61 @@ HIDDEN_IMPORTS = [ "qrcode", "aiohttp", "pynput", + "pynput._info", + "pynput._util", + "pynput.keyboard", + "pynput.keyboard._base", + "pynput.mouse", + "pynput.mouse._base", "pyperclip", "certifi", ] +PLATFORM_HIDDEN_IMPORTS = { + "Linux": [ + "pynput.keyboard._xorg", + "pynput.mouse._xorg", + "pynput._util.xorg", + "pynput._util.xorg_keysyms", + "pynput._util.uinput", + "pynput.keyboard._uinput", + "pynput.keyboard._dummy", + "pynput.mouse._dummy", + "Xlib", + "Xlib.display", + "Xlib.ext", + "Xlib.ext.xtest", + "Xlib.XK", + "Xlib.X", + "Xlib.protocol", + "Xlib.protocol.display", + "Xlib.protocol.event", + "Xlib.protocol.request", + "Xlib.protocol.rq", + "Xlib.protocol.structs", + "Xlib.keysymdef", + "Xlib.keysymdef.xkb", + "Xlib.keysymdef.latin1", + "Xlib.keysymdef.miscellany", + ], + "Windows": [ + "pynput.keyboard._win32", + "pynput.mouse._win32", + "pynput._util.win32", + "pynput._util.win32_vks", + "pynput.keyboard._dummy", + "pynput.mouse._dummy", + ], + "Darwin": [ + "pynput.keyboard._darwin", + "pynput.mouse._darwin", + "pynput._util.darwin", + "pynput._util.darwin_vks", + "pynput.keyboard._dummy", + "pynput.mouse._dummy", + ], +} + EXCLUDED_MODULES = [ "tkinter", "_tkinter", @@ -232,6 +283,8 @@ def build( for hidden_import in HIDDEN_IMPORTS: cmd.append(f"--hidden-import={hidden_import}") + for platform_hidden in PLATFORM_HIDDEN_IMPORTS.get(system, []): + cmd.append(f"--hidden-import={platform_hidden}") for excluded in EXCLUDED_MODULES: cmd.append(f"--exclude-module={excluded}") diff --git a/server/keyboard_controller.py b/server/keyboard_controller.py index f8e6c8e..07e654c 100644 --- a/server/keyboard_controller.py +++ b/server/keyboard_controller.py @@ -331,13 +331,35 @@ class KeyboardSimulator: loop = asyncio.get_running_loop() return await loop.run_in_executor(None, self._sync_type, full_text, active_suffix, active_mode) + def _ensure_controller(self) -> bool: + if self.controller is not None: + return True + global _controller, Controller, Key, KeyCode + try: + from pynput.keyboard import Controller as _C, Key as _K, KeyCode as _KC + Controller = _C + Key = _K + KeyCode = _KC + self.controller = Controller() + _controller = self.controller + self._linux_xtest, self._win32_helper = _init_platform_helpers(self.controller) + print("[+] Controller tastiera pynput inizializzato con successo.") + return True + except Exception as e: + print(f"Errore inizializzazione controller tastiera: {e}") + return False + def _tap_special(self, x11_name: str, pynput_key) -> None: + if not self._ensure_controller(): + return if self._linux_xtest is not None: if self._linux_xtest.tap_named(x11_name): return self.controller.tap(pynput_key) def _type_single_char(self, char: str) -> None: + if not self._ensure_controller(): + return if self._linux_xtest is not None: if self._linux_xtest.type_char(char): return @@ -380,6 +402,9 @@ class KeyboardSimulator: time.sleep(0.04) return True + if not self._ensure_controller(): + return False + modifier = Key.cmd if self.is_mac else Key.ctrl paste_key = KeyCode.from_vk(0x56) if (self.is_windows and KeyCode is not None) else "v" with self.controller.pressed(modifier): @@ -388,7 +413,7 @@ class KeyboardSimulator: return True def _sync_type(self, full_text: str, suffix: str, mode: str) -> bool: - if not self.controller: + if not self._ensure_controller(): print("Errore: controller tastiera non disponibile!") return False diff --git a/server/version.py b/server/version.py index d6951f1..5202793 100644 --- a/server/version.py +++ b/server/version.py @@ -7,7 +7,7 @@ APP_NAME = "Barcode Reader Server" APP_BINARY_NAME = "BarcodeServer" APP_ID = "com.catellisrl.barcodereader" APP_PUBLISHER = "Catelli Srl" -APP_VERSION = "1.0.1" +APP_VERSION = "1.0.2" GITEA_BASE_URL = "https://gitea.catelli.it" GITEA_REPO = "brontomark/barcode_reader_pc"