mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 07:07:13 -05:00
Merge pull request #412 from glutanimate/ankiaddon-filetype-handling-followup
Follow-up to .ankiaddon file-type handling
This commit is contained in:
commit
cc5ee87385
2 changed files with 36 additions and 17 deletions
|
|
@ -345,7 +345,7 @@ and have been disabled: %(found)s"
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _installationErrorReport(
|
def _installationErrorReport(
|
||||||
self, result: AddonInstallationResult, base: str, mode="download"
|
self, result: AddonInstallationResult, base: str, mode: str = "download"
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
|
|
||||||
messages = {
|
messages = {
|
||||||
|
|
@ -370,7 +370,7 @@ and have been disabled: %(found)s"
|
||||||
return [template % dict(base=name, id=name, error=msg)]
|
return [template % dict(base=name, id=name, error=msg)]
|
||||||
|
|
||||||
def _installationSuccessReport(
|
def _installationSuccessReport(
|
||||||
self, result: AddonInstallationResult, base: str, mode="download"
|
self, result: AddonInstallationResult, base: str, mode: str = "download"
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
|
|
||||||
if mode == "download": # preserve old format strings for i18n
|
if mode == "download": # preserve old format strings for i18n
|
||||||
|
|
@ -385,7 +385,7 @@ and have been disabled: %(found)s"
|
||||||
strings.append(
|
strings.append(
|
||||||
_("The following conflicting add-ons were disabled:")
|
_("The following conflicting add-ons were disabled:")
|
||||||
+ " "
|
+ " "
|
||||||
+ " ".join(result.conflicts)
|
+ ", ".join(self.addonName(f) for f in result.conflicts)
|
||||||
)
|
)
|
||||||
|
|
||||||
return strings
|
return strings
|
||||||
|
|
@ -666,7 +666,7 @@ class AddonsDialog(QDialog):
|
||||||
def onGetAddons(self):
|
def onGetAddons(self):
|
||||||
GetAddons(self)
|
GetAddons(self)
|
||||||
|
|
||||||
def onInstallFiles(self, paths: Optional[List[str]] = None, external: bool = False):
|
def onInstallFiles(self, paths: Optional[List[str]] = None):
|
||||||
if not paths:
|
if not paths:
|
||||||
key = _("Packaged Anki Add-on") + " (*{})".format(self.mgr.ext)
|
key = _("Packaged Anki Add-on") + " (*{})".format(self.mgr.ext)
|
||||||
paths = getFile(
|
paths = getFile(
|
||||||
|
|
@ -859,18 +859,20 @@ 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,
|
||||||
|
advise_restart: 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 +890,11 @@ def installAddonPackages(
|
||||||
|
|
||||||
if log:
|
if log:
|
||||||
log_html = "<br>".join(log)
|
log_html = "<br>".join(log)
|
||||||
if external:
|
if advise_restart:
|
||||||
log_html += "<br><br>" + _(
|
log_html += "<br><br>" + _(
|
||||||
"<b>Please restart Anki to complete the installation.</b>"
|
"<b>Please restart Anki to complete the installation.</b>"
|
||||||
)
|
)
|
||||||
if len(log) == 1:
|
if len(log) == 1 and not strictly_modal:
|
||||||
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.
|
||||||
|
|
@ -334,7 +334,10 @@ close the profile or restart Anki."""
|
||||||
|
|
||||||
# import pending?
|
# import pending?
|
||||||
if self.pendingImport:
|
if self.pendingImport:
|
||||||
self.handleImport(self.pendingImport)
|
if self._isAddon(self.pendingImport):
|
||||||
|
self.installAddon(self.pendingImport)
|
||||||
|
else:
|
||||||
|
self.handleImport(self.pendingImport)
|
||||||
self.pendingImport = None
|
self.pendingImport = None
|
||||||
runHook("profileLoaded")
|
runHook("profileLoaded")
|
||||||
if onsuccess:
|
if onsuccess:
|
||||||
|
|
@ -747,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()
|
||||||
|
|
||||||
|
|
@ -1025,10 +1032,17 @@ 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)
|
installAddonPackages(
|
||||||
|
self.addonManager,
|
||||||
|
[path],
|
||||||
|
warn=True,
|
||||||
|
advise_restart=not startup,
|
||||||
|
strictly_modal=startup,
|
||||||
|
parent=None if startup else self,
|
||||||
|
)
|
||||||
|
|
||||||
# Cramming
|
# Cramming
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
@ -1482,7 +1496,7 @@ will be lost. Continue?"""
|
||||||
self.app.appMsg.connect(self.onAppMsg)
|
self.app.appMsg.connect(self.onAppMsg)
|
||||||
|
|
||||||
def onAppMsg(self, buf: str) -> Optional[QTimer]:
|
def onAppMsg(self, buf: str) -> Optional[QTimer]:
|
||||||
is_addon = buf.endswith(".ankiaddon")
|
is_addon = self._isAddon(buf)
|
||||||
|
|
||||||
if self.state == "startup":
|
if self.state == "startup":
|
||||||
# try again in a second
|
# try again in a second
|
||||||
|
|
@ -1531,6 +1545,9 @@ Please ensure a profile is open and Anki is not busy, then try again."""
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _isAddon(self, buf: str) -> bool:
|
||||||
|
return buf.endswith(self.addonManager.ext)
|
||||||
|
|
||||||
# GC
|
# GC
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# ensure gc runs in main thread
|
# ensure gc runs in main thread
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue