From 0e5dea4c9f6cf5a03dbdaa0890d863fd787e8f32 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 15 Feb 2020 15:03:43 +0100 Subject: [PATCH] Assume that web assets without a specified subpath are under /_anki Maintains compatibility with existing add-ons --- qt/aqt/browser.py | 12 ++++++------ qt/aqt/clayout.py | 20 +++++++------------- qt/aqt/deckbrowser.py | 4 ++-- qt/aqt/editor.py | 4 ++-- qt/aqt/overview.py | 4 ++-- qt/aqt/reviewer.py | 16 ++++++++-------- qt/aqt/stats.py | 2 +- qt/aqt/toolbar.py | 6 ++---- qt/aqt/webview.py | 11 ++++++++--- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 5e8220ace..033f810c1 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1643,16 +1643,16 @@ where id in %s""" def _setupPreviewWebview(self): jsinc = [ - "_anki/jquery.js", - "_anki/browsersel.js", - "_anki/mathjax/conf.js", - "_anki/mathjax/MathJax.js", - "_anki/reviewer.js", + "jquery.js", + "browsersel.js", + "mathjax/conf.js", + "mathjax/MathJax.js", + "reviewer.js", ] web_context = PreviewDialog(dialog=self._previewWindow, browser=self) self._previewWeb.stdHtml( self.mw.reviewer.revHtml(), - css=["_anki/reviewer.css"], + css=["reviewer.css"], js=jsinc, context=web_context, ) diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py index 5dbc9ce90..87084cd8b 100644 --- a/qt/aqt/clayout.py +++ b/qt/aqt/clayout.py @@ -208,23 +208,17 @@ class CardLayout(QDialog): pform.backWeb = AnkiWebView(title="card layout back") pform.backPrevBox.addWidget(pform.backWeb) jsinc = [ - "_anki/jquery.js", - "_anki/browsersel.js", - "_anki/mathjax/conf.js", - "_anki/mathjax/MathJax.js", - "_anki/reviewer.js", + "jquery.js", + "browsersel.js", + "mathjax/conf.js", + "mathjax/MathJax.js", + "reviewer.js", ] pform.frontWeb.stdHtml( - self.mw.reviewer.revHtml(), - css=["_anki/reviewer.css"], - js=jsinc, - context=self, + self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self, ) pform.backWeb.stdHtml( - self.mw.reviewer.revHtml(), - css=["_anki/reviewer.css"], - js=jsinc, - context=self, + self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self, ) pform.frontWeb.set_bridge_command(self._on_bridge_cmd, self) pform.backWeb.set_bridge_command(self._on_bridge_cmd, self) diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index af4785254..a57647d62 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -107,8 +107,8 @@ class DeckBrowser: stats = self._renderStats() self.web.stdHtml( self._body % dict(tree=tree, stats=stats, countwarn=self._countWarn()), - css=["_anki/deckbrowser.css"], - js=["_anki/jquery.js", "_anki/jquery-ui.js", "_anki/deckbrowser.js"], + css=["deckbrowser.css"], + js=["jquery.js", "jquery-ui.js", "deckbrowser.js"], context=self, ) self.web.key = "deckBrowser" diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 257131351..b5974e371 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -164,8 +164,8 @@ class Editor: # then load page self.web.stdHtml( _html % (bgcol, bgcol, topbuts, _("Show Duplicates")), - css=["_anki/editor.css"], - js=["_anki/jquery.js", "_anki/editor.js"], + css=["editor.css"], + js=["jquery.js", "editor.js"], context=self, ) diff --git a/qt/aqt/overview.py b/qt/aqt/overview.py index e0500b612..e94b69953 100644 --- a/qt/aqt/overview.py +++ b/qt/aqt/overview.py @@ -149,8 +149,8 @@ class Overview: desc=self._desc(deck), table=self._table(), ), - css=["_anki/overview.css"], - js=["_anki/jquery.js", "_anki/overview.js"], + css=["overview.css"], + js=["jquery.js", "overview.js"], context=self, ) diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py index 59f9c379b..9200b15f6 100644 --- a/qt/aqt/reviewer.py +++ b/qt/aqt/reviewer.py @@ -145,13 +145,13 @@ class Reviewer: # main window self.web.stdHtml( self.revHtml(), - css=["_anki/reviewer.css"], + css=["reviewer.css"], js=[ - "_anki/jquery.js", - "_anki/browsersel.js", - "_anki/mathjax/conf.js", - "_anki/mathjax/MathJax.js", - "_anki/reviewer.js", + "jquery.js", + "browsersel.js", + "mathjax/conf.js", + "mathjax/MathJax.js", + "reviewer.js", ], context=self, ) @@ -159,8 +159,8 @@ class Reviewer: self.bottom.web.show() self.bottom.web.stdHtml( self._bottomHTML(), - css=["_anki/toolbar-bottom.css", "_anki/reviewer-bottom.css"], - js=["_anki/jquery.js", "_anki/reviewer-bottom.js"], + css=["toolbar-bottom.css", "reviewer-bottom.css"], + js=["jquery.js", "reviewer-bottom.js"], context=ReviewerBottomBar(self), ) diff --git a/qt/aqt/stats.py b/qt/aqt/stats.py index 33f4c5168..3a57d85f0 100644 --- a/qt/aqt/stats.py +++ b/qt/aqt/stats.py @@ -98,7 +98,7 @@ class DeckStats(QDialog): self.form.web.title = "deck stats" self.form.web.stdHtml( "" + self.report + "", - js=["_anki/jquery.js", "_anki/plot.js"], + js=["jquery.js", "plot.js"], context=self, ) self.mw.progress.finish() diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index a7ce013e2..088a371e0 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -49,9 +49,7 @@ class Toolbar: link_handler = link_handler or self._linkHandler self.web.set_bridge_command(link_handler, web_context) self.web.stdHtml( - self._body % self._centerLinks(), - css=["_anki/toolbar.css"], - context=web_context, + self._body % self._centerLinks(), css=["toolbar.css"], context=web_context, ) self.web.adjustHeightToFit() @@ -147,7 +145,7 @@ class BottomBar(Toolbar): self.web.set_bridge_command(link_handler, web_context) self.web.stdHtml( self._centerBody % buf, - css=["_anki/toolbar.css", "_anki/toolbar-bottom.css"], + css=["toolbar.css", "toolbar-bottom.css"], context=web_context, ) self.web.adjustHeightToFit() diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py index 1756797c9..d001c2a1c 100644 --- a/qt/aqt/webview.py +++ b/qt/aqt/webview.py @@ -327,8 +327,8 @@ class AnkiWebView(QWebEngineView): # type: ignore web_content = WebContent( body=body, head=head, - js=["_anki/webview.js"] + (["_anki/jquery.js"] if js is None else js), - css=["_anki/webview.css"] + ([] if css is None else css), + js=["webview.js"] + (["jquery.js"] if js is None else js), + css=["webview.css"] + ([] if css is None else css), ) gui_hooks.webview_will_set_content(web_content, context) @@ -411,7 +411,12 @@ body {{ zoom: {}; background: {}; {} }} def webBundlePath(self, path: str) -> str: from aqt import mw - return "http://127.0.0.1:%d/%s" % (mw.mediaServer.getPort(), path) + if path.startswith("/"): + subpath = "" + else: + subpath = "/_anki/" + + return f"http://127.0.0.1:{mw.mediaServer.getPort()}{subpath}{path}" def bundledScript(self, fname: str) -> str: return '' % self.webBundlePath(fname)