From 8b5d330981bb52cfc26650be27a79b648bf372a4 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 18 Jul 2021 21:14:06 -0400 Subject: [PATCH] Use gui_hooks for playAudio JS bridge to avoid affecting other addons and respect docs --- src/main.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/main.py b/src/main.py index 55e8dba..a1a8339 100644 --- a/src/main.py +++ b/src/main.py @@ -12,7 +12,7 @@ from aqt.utils import shortcut, saveGeom, saveSplitter, showInfo import aqt.editor import json -from aqt import mw +from aqt import mw, gui_hooks from aqt.qt import * import copy from .miutils import miInfo @@ -352,27 +352,12 @@ def clickPlayAudio(cmd): if exists(path): sound.play(path) -def revBridgeReroute(self, cmd): +def audioBridgeHandler(handled, cmd, context): if cmd.startswith('playAudio;'): if checkProfile() and getConfig()['PlayAudioOnClick'] == 'on': clickPlayAudio(cmd) - return - else: - ogRevReroute(self, cmd) - -ogRevReroute = aqt.reviewer.Reviewer._linkHandler -aqt.reviewer.Reviewer._linkHandler = revBridgeReroute - -def prevBridgeReroute(self, cmd): - if cmd.startswith('playAudio;'): - if checkProfile() and getConfig()['PlayAudioOnClick'] == 'on': - clickPlayAudio(cmd) - return - else: - ogAnkiWebBridge(self, cmd) - - + return (True, None) + return handled -ogAnkiWebBridge = AnkiWebView._onBridgeCmd -AnkiWebView._onBridgeCmd = prevBridgeReroute +gui_hooks.webview_did_receive_js_message.append(audioBridgeHandler)