You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-30 23:44:55 +02:00
Plugins: Allow posting messages from plugin to webview (#5569)
This commit is contained in:
@ -44,14 +44,14 @@ export default class JoplinViewsPanels {
|
||||
/**
|
||||
* Sets the panel webview HTML
|
||||
*/
|
||||
public async setHtml(handle: ViewHandle, html: string) {
|
||||
public async setHtml(handle: ViewHandle, html: string): Promise<string> {
|
||||
return this.controller(handle).html = html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds and loads a new JS or CSS files into the panel.
|
||||
*/
|
||||
public async addScript(handle: ViewHandle, scriptPath: string) {
|
||||
public async addScript(handle: ViewHandle, scriptPath: string): Promise<void> {
|
||||
return this.controller(handle).addScript(scriptPath);
|
||||
}
|
||||
|
||||
@ -74,10 +74,30 @@ export default class JoplinViewsPanels {
|
||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages) for more details.
|
||||
*
|
||||
*/
|
||||
public async onMessage(handle: ViewHandle, callback: Function) {
|
||||
public async onMessage(handle: ViewHandle, callback: Function): Promise<void> {
|
||||
return this.controller(handle).onMessage(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the webview.
|
||||
*
|
||||
* The webview must have registered a message handler prior, otherwise the message is ignored. Use;
|
||||
*
|
||||
* ```javascript
|
||||
* webviewApi.onMessage((message) => { ... });
|
||||
* ```
|
||||
*
|
||||
* - `message` can be any JavaScript object, string or number
|
||||
*
|
||||
* The view API may have only one onMessage handler defined.
|
||||
* This method is fire and forget so no response is returned.
|
||||
*
|
||||
* It is particularly useful when the webview needs to react to events emitted by the plugin or the joplin api.
|
||||
*/
|
||||
public postMessage(handle: ViewHandle, message: any): void {
|
||||
return this.controller(handle).postMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the panel
|
||||
*/
|
||||
|
Reference in New Issue
Block a user