mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-01-31 00:45:24 +01:00
* refactor: only inject API IIFE script when withGlobalTauri is true * fmt * update tauri
50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//! [](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/http)
|
|
//!
|
|
//! Access the HTTP client written in Rust.
|
|
|
|
pub use reqwest;
|
|
use tauri::{
|
|
plugin::{Builder, TauriPlugin},
|
|
AppHandle, Manager, Runtime,
|
|
};
|
|
|
|
pub use error::{Error, Result};
|
|
|
|
mod commands;
|
|
mod error;
|
|
mod scope;
|
|
|
|
struct Http<R: Runtime> {
|
|
#[allow(dead_code)]
|
|
app: AppHandle<R>,
|
|
}
|
|
|
|
trait HttpExt<R: Runtime> {
|
|
fn http(&self) -> &Http<R>;
|
|
}
|
|
|
|
impl<R: Runtime, T: Manager<R>> HttpExt<R> for T {
|
|
fn http(&self) -> &Http<R> {
|
|
self.state::<Http<R>>().inner()
|
|
}
|
|
}
|
|
|
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
Builder::<R>::new("http")
|
|
.invoke_handler(tauri::generate_handler![
|
|
commands::fetch,
|
|
commands::fetch_cancel,
|
|
commands::fetch_send,
|
|
commands::fetch_read_body,
|
|
])
|
|
.setup(|app, _api| {
|
|
app.manage(Http { app: app.clone() });
|
|
Ok(())
|
|
})
|
|
.build()
|
|
}
|