diff --git a/custom_lemmas.py b/custom_lemmas.py index 70996b9..5c90df0 100644 --- a/custom_lemmas.py +++ b/custom_lemmas.py @@ -32,7 +32,12 @@ ) from .error_dialogs import device_not_found_dialog, ww_db_not_found_dialog -from .send_file import copy_klld_from_android, copy_klld_from_kindle, device_connected +from .send_file import ( + copy_klld_from_android, + copy_klld_from_kindle, + device_connected, + is_mtp_device, +) from .utils import ( custom_lemmas_folder, get_kindle_klld_path, @@ -217,6 +222,8 @@ def check_empty_kindle_gloss(self) -> None: if not package_name: device_not_found_dialog(self) return + if is_mtp_device(gui.device_manager.device): + return custom_folder = custom_lemmas_folder(plugin_path, "en") if isinstance(package_name, str): copy_klld_from_android(package_name, custom_folder) diff --git a/send_file.py b/send_file.py index 6fb5dbe..9c939cc 100644 --- a/send_file.py +++ b/send_file.py @@ -100,7 +100,7 @@ def send_files(self, job: Any) -> None: ) def move_files_to_kindle(self, device_driver: Any, device_book_path: Path) -> None: - use_mtp = getattr(device_driver, "DEVICE_PLUGBOARD_NAME", "") == "MTP_DEVICE" + use_mtp = is_mtp_device(device_driver) if not use_mtp: # _main_prefix: Kindle mount point, /Volumes/Kindle device_mount_point = Path(device_driver._main_prefix) @@ -172,7 +172,16 @@ def push_files_to_android(self, adb_path: str) -> None: def device_connected(gui: Any, book_fmt: str) -> str | bool: if gui.device_manager.is_device_present: - is_kindle = getattr(gui.device_manager.device, "VENDOR_ID", None) == [0x1949] + is_kindle = False + device = gui.device_manager.device + if hasattr(device, "VENDOR_NAME"): + # Normal USB mass storage Kindle + is_kindle = device.VENDOR_NAME == "KINDLE" + elif hasattr(device, "current_vid"): + # Kindle Scribe, MTP vendor id is Amazon + # https://github.com/kovidgoyal/calibre/blob/475b0d3d2e6678dc4fd5441619f71a048c3806ea/src/calibre/devices/mtp/driver.py#L145 + is_kindle = device.current_vid == 0x1949 + if book_fmt == "EPUB": if is_kindle: kindle_epub_dialog(gui) @@ -188,6 +197,13 @@ def device_connected(gui: Any, book_fmt: str) -> str | bool: return False +def is_mtp_device(device_driver: Any) -> bool: + # https://github.com/kovidgoyal/calibre/blob/475b0d3d2e6678dc4fd5441619f71a048c3806ea/src/calibre/devices/mtp/driver.py#L49 + if hasattr(device_driver, "DEVICE_PLUGBOARD_NAME"): + return device_driver.DEVICE_PLUGBOARD_NAME == "MTP_DEVICE" + return False + + def adb_connected(adb_path: str) -> bool: r = run_subprocess([adb_path, "devices"]) return r.stdout.decode().strip().endswith("device") if r else False