/
githubmirror
/
tauri
Обзор
Документация
Войти
/
githubmirror
/
tauri
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
examples/api/src-tauri/tauri-plugin-sample/src/lib.rs
87 строк
2 KB
sftse
enhance: remove `T: Send + Sync` requirement from `State<'r, T>` (#15578)
06 июл 2026, 17:09
Не верифицирован
06 июл 2026, 17:09
d3108ff
Код
Авторство
О чём код?
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT use serde::Deserialize; use std::path::PathBuf; use tauri::{ plugin::{Builder, TauriPlugin}, Manager, Runtime, State, }; pub use models::*; #[cfg(desktop)] mod desktop; #[cfg(mobile)] mod mobile; mod error; mod models; #[cfg(desktop)] use desktop::Sample; #[cfg(mobile)] use mobile::Sample; pub use error::*; /// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the sample APIs. pub trait SampleExt<R: Runtime> { fn sample(&self) -> State<'_, Sample<R>>; } impl<R: Runtime, T: Manager<R>> crate::SampleExt<R> for T { fn sample(&self) -> State<'_, Sample<R>> { self.state::<Sample<R>>() } } #[allow(dead_code)] #[derive(Debug, Deserialize)] struct PingScope { path: PathBuf, } #[allow(dead_code)] #[derive(Debug, Deserialize)] struct SampleScope { path: PathBuf, } #[tauri::command] fn ping<R: tauri::Runtime>( app: tauri::AppHandle<R>, value: Option<String>, scope: tauri::ipc::CommandScope<PingScope>, global_scope: tauri::ipc::GlobalScope<SampleScope>, ) -> std::result::Result<PingResponse, String> { println!("local scope {scope:?}"); println!("global scope {global_scope:?}"); app .sample() .ping(PingRequest { value, on_event: tauri::ipc::Channel::new(|_| Ok(())), }) .map_err(|e| e.to_string()) } pub fn init<R: Runtime>() -> TauriPlugin<R> { Builder::new("sample") .setup(|app, api| { #[cfg(mobile)] let sample = mobile::init(app, api)?; #[cfg(desktop)] let sample = desktop::init(app, api)?; app.manage(sample); Ok(()) }) .invoke_handler(tauri::generate_handler![ping]) .on_navigation(|window, url| { println!("navigation {} {url}", window.label()); true }) .build() }