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

Conversation

jamesrwaugh
Copy link

@jamesrwaugh jamesrwaugh commented Jul 20, 2021

Resolves #92

Hi,

I'm developing an Anki addon and I found how Migaku is "hijacking" the private AnkiWebView _onBridgeCmd prevents a JS callback from being called when handing a pycmd on new webviews.

The real issue is that prevBridgeReroute in main.py should have a return statement on the last line, like this, so the results can be passed to a JavaScript callback.

def prevBridgeReroute(self, cmd):
    if cmd.startswith('playAudio;'):
        if checkProfile() and getConfig()['PlayAudioOnClick'] == 'on':
            clickPlayAudio(cmd)
            return
    else:
        return ogAnkiWebBridge(self, cmd)

But, the docs recommended using gui_hooks.webview_did_receive_js_message here which I think is the cleaner choice. When I make this change, it resolves the issue. Did a test on my Linux machine and the on-click audio still works as expected.
https://addon-docs.ankiweb.net/#/hooks-and-filters?id=webview

webview.py in Anki also discourages setting _onBridgeCmd and onBridgeCmd manually:

# in new code, use .set_bridge_command() instead of setting this directly
self.onBridgeCmd: Callable[[str], Any] = self.defaultOnBridgeCmd

I'd be happy to make a small addon to show further reproduction steps if needed.

@ghost ghost closed this by deleting the head repository Aug 20, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grabbing _onBridgeCmd interfereing with other addons using JS bridge
1 participant