mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
When possible, install add-on before add-ons are loaded
Removes the need to restart Anki if it is not running when user launches .ankiaddon file
This commit is contained in:
parent
d9e56e22f9
commit
6a7f11b172
2 changed files with 19 additions and 14 deletions
|
@ -859,18 +859,19 @@ class ConfigEditor(QDialog):
|
||||||
def installAddonPackages(
|
def installAddonPackages(
|
||||||
addonsManager: AddonManager,
|
addonsManager: AddonManager,
|
||||||
paths: List[str],
|
paths: List[str],
|
||||||
parent: QWidget = None,
|
parent: Optional[QWidget] = None,
|
||||||
external: bool = False,
|
warn: bool = False,
|
||||||
|
strictly_modal: bool = False
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
if external:
|
if warn:
|
||||||
names = ",<br>".join(f"<b>{os.path.basename(p)}</b>" for p in paths)
|
names = ",<br>".join(f"<b>{os.path.basename(p)}</b>" for p in paths)
|
||||||
q = _(
|
q = _(
|
||||||
"<b>Important</b>: As add-ons are programs downloaded from the internet, "
|
"<b>Important</b>: As add-ons are programs downloaded from the internet, "
|
||||||
"they are potentially malicious."
|
"they are potentially malicious."
|
||||||
"<b>You should only install add-ons you trust.</b><br><br>"
|
"<b>You should only install add-ons you trust.</b><br><br>"
|
||||||
"Are you sure you want to proceed with the installation of the "
|
"Are you sure you want to proceed with the installation of the "
|
||||||
"following add-on(s)?<br><br>%(names)s"
|
"following Anki add-on(s)?<br><br>%(names)s"
|
||||||
) % dict(names=names)
|
) % dict(names=names)
|
||||||
if (
|
if (
|
||||||
not showInfo(
|
not showInfo(
|
||||||
|
@ -888,11 +889,7 @@ def installAddonPackages(
|
||||||
|
|
||||||
if log:
|
if log:
|
||||||
log_html = "<br>".join(log)
|
log_html = "<br>".join(log)
|
||||||
if external:
|
if len(log) == 1 and not strictly_modal:
|
||||||
log_html += "<br><br>" + _(
|
|
||||||
"<b>Please restart Anki to complete the installation.</b>"
|
|
||||||
)
|
|
||||||
if len(log) == 1:
|
|
||||||
tooltip(log_html, parent=parent)
|
tooltip(log_html, parent=parent)
|
||||||
else:
|
else:
|
||||||
showInfo(
|
showInfo(
|
||||||
|
|
|
@ -72,7 +72,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.safeMode = self.app.queryKeyboardModifiers() & Qt.ShiftModifier
|
self.safeMode = self.app.queryKeyboardModifiers() & Qt.ShiftModifier
|
||||||
try:
|
try:
|
||||||
self.setupUI()
|
self.setupUI()
|
||||||
self.setupAddons()
|
self.setupAddons(args)
|
||||||
except:
|
except:
|
||||||
showInfo(_("Error during startup:\n%s") % traceback.format_exc())
|
showInfo(_("Error during startup:\n%s") % traceback.format_exc())
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -85,7 +85,7 @@ class AnkiQt(QMainWindow):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# were we given a file to import?
|
# 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])
|
self.onAppMsg(args[0])
|
||||||
# Load profile in a timer so we can let the window finish init and not
|
# Load profile in a timer so we can let the window finish init and not
|
||||||
# close on profile load error.
|
# close on profile load error.
|
||||||
|
@ -750,10 +750,14 @@ title="%s" %s>%s</button>""" % (
|
||||||
|
|
||||||
self.errorHandler = aqt.errors.ErrorHandler(self)
|
self.errorHandler = aqt.errors.ErrorHandler(self)
|
||||||
|
|
||||||
def setupAddons(self) -> None:
|
def setupAddons(self, args: Optional[List]) -> None:
|
||||||
import aqt.addons
|
import aqt.addons
|
||||||
|
|
||||||
self.addonManager = aqt.addons.AddonManager(self)
|
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:
|
if not self.safeMode:
|
||||||
self.addonManager.loadAddons()
|
self.addonManager.loadAddons()
|
||||||
|
|
||||||
|
@ -1028,10 +1032,14 @@ QTreeWidget {
|
||||||
# Installing add-ons from CLI / mimetype handler
|
# Installing add-ons from CLI / mimetype handler
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def installAddon(self, path):
|
def installAddon(self, path: str, startup: bool = False):
|
||||||
from aqt.addons import installAddonPackages
|
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
|
# Cramming
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
Loading…
Reference in a new issue