Download packages/tauri/examples/api/src-tauri/tauri-plugin-sample/src/lib.rs from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri/examples/api/src-tauri/tauri-plugin-sample/src/lib.rs
- Command line
-
hf download hf://datasets/echodict/readest/packages/tauri/examples/api/src-tauri/tauri-plugin-sample/src/lib.rs
-
curl -L -o lib.rs https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri/examples/api/src-tauri/tauri-plugin-sample/src/lib.rs
1.88 kB
| // 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, | |
| }; | |
| pub use models::*; | |
| mod desktop; | |
| mod mobile; | |
| mod error; | |
| mod models; | |
| use desktop::Sample; | |
| 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) -> &Sample<R>; | |
| } | |
| impl<R: Runtime, T: Manager<R>> crate::SampleExt<R> for T { | |
| fn sample(&self) -> &Sample<R> { | |
| self.state::<Sample<R>>().inner() | |
| } | |
| } | |
| struct PingScope { | |
| path: PathBuf, | |
| } | |
| struct SampleScope { | |
| path: PathBuf, | |
| } | |
| 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| { | |
| let sample = mobile::init(app, api)?; | |
| 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() | |
| } | |