diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index 54bf35a50..06dacf442 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -859,18 +859,19 @@ class ConfigEditor(QDialog): def installAddonPackages( addonsManager: AddonManager, paths: List[str], - parent: QWidget = None, - external: bool = False, + parent: Optional[QWidget] = None, + warn: bool = False, + strictly_modal: bool = False ) -> bool: - if external: + if warn: names = ",
".join(f"{os.path.basename(p)}" for p in paths) q = _( "Important: As add-ons are programs downloaded from the internet, " "they are potentially malicious." "You should only install add-ons you trust.

" "Are you sure you want to proceed with the installation of the " - "following add-on(s)?

%(names)s" + "following Anki add-on(s)?

%(names)s" ) % dict(names=names) if ( not showInfo( @@ -888,11 +889,7 @@ def installAddonPackages( if log: log_html = "
".join(log) - if external: - log_html += "

" + _( - "Please restart Anki to complete the installation." - ) - if len(log) == 1: + if len(log) == 1 and not strictly_modal: tooltip(log_html, parent=parent) else: showInfo( diff --git a/qt/aqt/main.py b/qt/aqt/main.py index b6b69982f..81198238f 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -72,7 +72,7 @@ class AnkiQt(QMainWindow): self.safeMode = self.app.queryKeyboardModifiers() & Qt.ShiftModifier try: self.setupUI() - self.setupAddons() + self.setupAddons(args) except: showInfo(_("Error during startup:\n%s") % traceback.format_exc()) sys.exit(1) @@ -85,7 +85,7 @@ class AnkiQt(QMainWindow): ) ) # were we given a file to import? - if args and args[0]: + if args and args[0] and not self._isAddon(args[0]): self.onAppMsg(args[0]) # Load profile in a timer so we can let the window finish init and not # close on profile load error. @@ -750,10 +750,14 @@ title="%s" %s>%s""" % ( self.errorHandler = aqt.errors.ErrorHandler(self) - def setupAddons(self) -> None: + def setupAddons(self, args: Optional[List]) -> None: import aqt.addons self.addonManager = aqt.addons.AddonManager(self) + + if args and args[0] and self._isAddon(args[0]): + self.installAddon(args[0], startup=True) + if not self.safeMode: self.addonManager.loadAddons() @@ -1028,10 +1032,14 @@ QTreeWidget { # Installing add-ons from CLI / mimetype handler ########################################################################## - def installAddon(self, path): + def installAddon(self, path: str, startup: bool = False): from aqt.addons import installAddonPackages - installAddonPackages(self.addonManager, [path], external=True, parent=self) + parent = None if startup else self + + installAddonPackages( + self.addonManager, [path], warn=True, strictly_modal=startup, parent=parent + ) # Cramming ##########################################################################