From 5a07ef06e4e762e7c85391dc60f53a508c7e889e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 28 Oct 2023 11:59:54 +1000 Subject: [PATCH] Add 'copy debug info' button to add-on startup screen --- ftl/qt/addons.ftl | 3 +++ qt/aqt/addons.py | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/ftl/qt/addons.ftl b/ftl/qt/addons.ftl index 5765292b6..58f4c7e15 100644 --- a/ftl/qt/addons.ftl +++ b/ftl/qt/addons.ftl @@ -11,6 +11,9 @@ addons-failed-to-load2 = They may need to be updated to support this version of Anki. Click the { addons-check-for-updates } button to see if any updates are available. + You can use the { about-copy-debug-info } button to get information that you can paste in a report to + the add-on author. + For add-ons that don't have an update available, you can disable or delete the add-on to prevent this message from appearing. addons-startup-failed = Add-on Startup Failed diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index 63112259d..40a100f0a 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -49,6 +49,7 @@ from aqt.utils import ( showInfo, showText, showWarning, + supportText, tooltip, tr, ) @@ -229,7 +230,10 @@ class AddonManager: return os.path.join(root, module) def loadAddons(self) -> None: + from aqt import mw + broken: list[str] = [] + error_text = "" for addon in self.all_addon_meta(): if not addon.enabled: continue @@ -247,7 +251,9 @@ class AddonManager: broken.append(f"{name}") else: broken.append(name) - print(traceback.format_exc()) + tb = traceback.format_exc() + print(tb) + error_text += f"When loading {name}:\n{tb}\n" if broken: addons = "\n\n- " + "\n- ".join(broken) @@ -260,29 +266,36 @@ class AddonManager: (diag, box) = showText( html2, type="html", - copyBtn=True, run=False, ) - but = box.addButton( + + def on_check() -> None: + tooltip(tr.addons_checking()) + + def on_done(log: list[DownloadLogEntry]) -> None: + if not log: + tooltip(tr.addons_no_updates_available()) + + mw.check_for_addon_updates(by_user=True, on_done=on_done) + + def on_copy() -> None: + txt = supportText() + "\n" + error_text + QApplication.clipboard().setText(txt) + tooltip(tr.about_copied_to_clipboard(), parent=diag) + + check = box.addButton( tr.addons_check_for_updates(), QDialogButtonBox.ButtonRole.ActionRole ) - but.clicked.connect(self.check_for_updates_after_load_failure) - from aqt import mw + check.clicked.connect(on_check) + + copy = box.addButton( + tr.about_copy_debug_info(), QDialogButtonBox.ButtonRole.ActionRole + ) + copy.clicked.connect(on_copy) # calling show immediately appears to crash mw.progress.single_shot(1000, diag.show) - def check_for_updates_after_load_failure(self) -> None: - from aqt import mw - - tooltip(tr.addons_checking()) - - def on_done(log: list[DownloadLogEntry]) -> None: - if not log: - tooltip(tr.addons_no_updates_available()) - - mw.check_for_addon_updates(by_user=True, on_done=on_done) - def onAddonsDialog(self) -> None: aqt.dialogs.open("AddonsDialog", self)