Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reccomened gui_hooks for playAudio JS bridge to avoid affecting other addons #91

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)