SpotubeSpotube Docs

WebView

Documentation for the WebView API for spotube plugins

The hetu_spotube_plugin is a built-in module that plugin developers can use in their plugins.

import "module:spotube_plugin" as spotube

WebView API

The WebView API allows plugins to create and manage web views within the Spotube application.

Usage

First, an WebView instance needs to be created with uri.

import "module:spotube_plugin" as spotube

let webview = spotube.Webview(uri: "https://example.com")

To open the webview, you can use the open method:

webview.open() // returns Future<void>

To close the webview, you can use the close method:

webview.close() // returns Future<void>

Listening to URL changes

You can listen to url change events by using the onUrlRequestStream method. It's emitted when the URL of the webview changes, such as when the user navigates to a different page or clicks a link.

// Make sure to import the hetu_std and Stream
import "module:hetu_std" as std

var Stream = std.Stream

// ... created webview instance and other stuff

var subscription = webview.onUrlRequestStream().listen((url) {
    // Handle the URL change
    print("URL changed to: $url")
})

// Don't forget to cancel the subscription when it's no longer needed
subscription.cancel()

Retrieving cookies

To get cookies from the webview, you can use the getCookies method:

webview.getCookies("https://example.com") // returns Future<List<Cookie>>

You can find the Cookie class and all it's methods and properties in the hetu_spotube_plugin module source code

On this page