Dialog <-> Plugin Communication

I noticed that in the plugin API, specifically the dialogs. There's no onMessage event as in panels ? Why is that the case ?

And is there a workaround in order to send data back and forth between the plugin and the dialog webview ?

E: Just realized, onMessage method only seems to work for sending data from the view to the plugin. What if I want to do the opposite ?

What do you want to do?

Sending the input note contents and then receive it.

I think I already have an idea on how to get back the resulting note from here: How to get feedback (user input) from a dialog? - #8 by laurent

Still not sure if CodeMirror can act as a form though.

Regardless, I need a way to send in the 2 notes into the Webview. I don't think I can simply just hardcode them into the HTML as well..? As the DOM of CodeMirror is dynamically created?

Sounds like you could set the note content when you create the view, without the need for sending messages. Then to get the note back, the view can send messages to the plugin.

Dialogs don't have onMessage event.

Right, I think it came up before but the issue is that dialogs are supposed to be modal. So the user makes some changes, click Save, the modal is closed and you get the result back. Is there something more you'd need?

Hm. Yeah I still need to try that. My concern is that I'm unsure if CodeMirror can act a normal input field. (In order to get it's contents sent by Joplin).

Anyways,
I have another issue though that's stopping me, For some reason when Joplin is loading webview scripts, it somehow doesn't load them in correct order.

If I do this

await dialogs.addScript(diffViewDialog, './UI/codemirror/lib/codemirror.js');
await dialogs.addScript(diffViewDialog, './UI/codemirror/addon/merge/merge.js');

I will get an error that CodeMirror doesn't exist even though it's right there, as if it tried to load all scripts at once on dialog open.

The only way I got it to work is by delaying the call await dialogs.addScript(diffViewDialog, './UI/codemirror/addon/merge/merge.js'); until after the open function is called. (So that the view would be loaded already). But this solution isn't practical, I have to assume it's just a bug in Joplin that can be fixed ?

It doesn't have to. You're in control of the dialog content, so you can dynamically create hidden input fields and set the content to anything you want, which will be picked up by the dialog when it's closed.

1 Like

I just noticed, the intended way to use dialogs is to create it once when loading the plugin. And then use .open when it's needed. So I'm back to step 1. A delay wouldn't work or else I'd have to create a new dialog every time.

1 Like