Files
tauri/examples/api/src-tauri/tauri-plugin-sample/src/desktop.rs
Lucas Fernandes Nogueira f0da0bde87 feat(core): add WebviewWindow::resolve_command_scope (#11439)
* feat(core): add WebviewWindow::resolve_command_scope

This new functionality exposes the `CommandScope` resolution as a function (currently only commands can resolve them as a dependency injection via CommandItem)

This function is useful to validate the configuration at runtime (do some asserts at setup phase to ensure capabilities are properly configured) and to resolve scopes in a separate thread or context

* adjust return type
2024-10-21 15:16:08 -03:00

31 lines
776 B
Rust

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use serde::de::DeserializeOwned;
use tauri::{plugin::PluginApi, AppHandle, Runtime};
use crate::models::*;
pub fn init<R: Runtime, C: DeserializeOwned>(
app: &AppHandle<R>,
_api: PluginApi<R, C>,
) -> crate::Result<Sample<R>> {
Ok(Sample(app.clone()))
}
/// A helper class to access the sample APIs.
pub struct Sample<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Sample<R> {
pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
payload.on_event.send(Event {
kind: "ping".to_string(),
value: payload.value.clone(),
})?;
Ok(PingResponse {
value: payload.value,
})
}
}