From 69cd27ad55f244b8362bf164c301bdc860fa33db Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Thu, 7 Jan 2021 09:17:52 -0500 Subject: [PATCH] main_window/keyboard_comm: allow resuming interrupted unlock --- src/main/python/keyboard_comm.py | 8 ++++++++ src/main/python/main_window.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/main/python/keyboard_comm.py b/src/main/python/keyboard_comm.py index f70da72..cf9785a 100644 --- a/src/main/python/keyboard_comm.py +++ b/src/main/python/keyboard_comm.py @@ -309,6 +309,14 @@ class Keyboard: data = self.usb_send(self.dev, struct.pack("BB", CMD_VIA_VIAL_PREFIX, CMD_VIAL_GET_UNLOCK_STATUS)) return data[0] + def get_unlock_in_progress(self): + # VIA keyboards are never being unlocked + if self.vial_protocol < 0: + return 0 + + data = self.usb_send(self.dev, struct.pack("BB", CMD_VIA_VIAL_PREFIX, CMD_VIAL_GET_UNLOCK_STATUS)) + return data[1] + def get_unlock_keys(self): """ Return keys users have to hold to unlock the keyboard as a list of rowcols """ diff --git a/src/main/python/main_window.py b/src/main/python/main_window.py index 9a50055..cc5d1ac 100644 --- a/src/main/python/main_window.py +++ b/src/main/python/main_window.py @@ -158,6 +158,11 @@ class MainWindow(QMainWindow): # don't show "Security" menu for bootloader mode, as the bootloader is inherently insecure self.security_menu.menuAction().setVisible(isinstance(self.current_device, VialKeyboard)) + # if unlock process was interrupted, we must finish it first + if isinstance(self.current_device, VialKeyboard) and self.current_device.keyboard.get_unlock_in_progress(): + Unlocker.get().perform_unlock(self.current_device.keyboard) + self.current_device.keyboard.reload() + for e in [self.layout_editor, self.keymap_editor, self.firmware_flasher, self.macro_recorder]: e.rebuild(self.current_device)