Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Builds the plugin.

Takes a RouterBuilder rather than a finished Router so the base URL can be checked before the router is sealed, which is the only moment that mistake is still visible.

Implementations§

Source§

impl Builder

Source

pub fn new(router: RouterBuilder) -> Builder

Starts a plugin for router, on the DEFAULT_SCHEME.

Source

pub fn sessions(self, config: SessionConfigBuilder) -> Builder

Available on crate feature session only.

Installs topcoat sessions, carrying the token in this process.

let plugin = tauri_plugin_topcoat::Builder::new(Router::builder())
    .sessions(SessionConfig::builder())
    .build()?;
§Why you need this

topcoat’s session token rides a hardened cookie by default, and WebKit throws away every cookie a custom protocol sets. Your login would look like it worked and the next request would arrive anonymous. This swaps the transport and nothing else - minting, hashing, expiry, start and stop and rotate, and your own session storage all stay topcoat’s.

The token is held here, keyed by the webview that asked, and never crosses into the webview at all. Not document.cookie, not a header a script can read, not anything WebKit writes to disk. A browser has to hand a client its token because the server is somewhere else. Here it is the same process, and Tauri tells you which webview asked.

§What it costs

The token is ambient with respect to the webview, so whatever document that webview is showing can use it. Confinement is what defends that, so leaving allow_external_navigation off matters more once sessions are on. A webview seen on somebody else’s origin stops being handed the token either way.

Confinement governs navigation, not sub-resources: a document of yours embedding a foreign frame still shows your origin, so the token is still handed out, and what stops that frame spending it is topcoat’s origin check. Serve a Content-Security-Policy if you would rather it could not load.

Reach for this rather than topcoat’s own sessions, which keeps whatever token store the configuration carries - the cookie one, with topcoat’s cookie feature on, whose every sign-in answers 502.

§Panics

Never directly. Call this twice and the second store replaces the first, taking the first one’s tokens with it.

Source

pub fn scheme(self, scheme: impl Into<String>) -> Builder

Serves the application under a different scheme name.

The window’s URL must match: <scheme>://localhost/.

Source

pub const fn use_https_scheme(self, https: bool) -> Builder

Overrides WebviewWindowBuilder::use_https_scheme, which changes the URL shape on the platforms that rewrite custom schemes onto http.

Left alone, the plugin reads the same useHttpsScheme the webview does out of the application configuration, so there is no second place to keep in step. Set this only for a webview built in code with a setting the configuration does not carry.

Source

pub const fn allow_external_navigation(self, allow: bool) -> Builder

Lets a webview showing this application navigate to another origin.

Off by default. A desktop application usually wants an external link opened in the user’s browser rather than replacing its own UI, and a webview that cannot reach another origin cannot host content that would try to forge requests against this one.

Source

pub fn build<R: Runtime>(self) -> Result<TauriPlugin<R>, Error>

Builds the plugin.

§Errors

Error::Scheme if the scheme name is unusable, and Error::BaseUrlCollision if the router’s base URL is the origin this protocol serves.

Source

pub fn session(self, platform: Platform) -> Result<Session, Error>

Drives the same application without a window, as platform would.

Everything configured here applies, sessions included, so a test exercises the transport the application actually runs on. Naming the platform lets a test check a request the way Windows delivers it while running on macOS.

§Errors

The same as Builder::build.

Trait Implementations§

Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The router is the bulk of the value and has no Debug of its own, so what is shown is the configuration a reader would be checking.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more