1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//! Get application metadata.
//!
//! he APIs must be added to tauri.allowlist.app in tauri.conf.json:
//! ```json
//! {
//! "tauri": {
//! "allowlist": {
//! "app": {
//! "all": true, // enable all app APIs
//! "show": true,
//! "hide": true
//! }
//! }
//! }
//! }
//! ```
//! It is recommended to allowlist only the APIs you use for optimal bundle size and security.
use semver::Version;
/// Gets the application name.
///
/// # Example
///
/// ```typescript
/// import { getName } from '@tauri-apps/api/app';
/// const appName = await getName();
/// ```
#[inline(always)]
pub async fn get_name() -> crate::Result<String> {
let js_val = inner::getName().await?;
Ok(serde_wasm_bindgen::from_value(js_val)?)
}
/// Gets the application version.
///
/// # Example
///
/// ```rust,no_run
/// use tauri_api::app::get_version;
///
/// let version = get_version().await;
/// ```
#[inline(always)]
pub async fn get_version() -> crate::Result<Version> {
let js_val = inner::getVersion().await?;
Ok(serde_wasm_bindgen::from_value(js_val)?)
}
/// Gets the Tauri version.
///
/// # Example
///
/// ```rust,no_run
/// use tauri_app::app:get_tauri_version;
///
/// let version = get_tauri_version().await;
/// ```
#[inline(always)]
pub async fn get_tauri_version() -> crate::Result<Version> {
let js_val = inner::getTauriVersion().await?;
Ok(serde_wasm_bindgen::from_value(js_val)?)
}
/// Shows the application on macOS. This function does not automatically focus the apps windows.
///
/// # Example
///
/// ```rust,no_run
/// use tauri_api::app::show;
///
/// show().await;
/// ```
///
/// Requires [`allowlist > app > show`](https://tauri.app/v1/api/config#appallowlistconfig.show) to be enabled.
#[inline(always)]
pub async fn show() -> crate::Result<()> {
Ok(inner::show().await?)
}
/// Hides the application on macOS.
///
/// # Example
///
/// ```rust,no_run
/// use tauri_api::app::hide;
///
/// hide().await;
/// ```
///
/// Requires [`allowlist > app > hide`](https://tauri.app/v1/api/config#appallowlistconfig.hide) to be enabled.
#[inline(always)]
pub async fn hide() -> crate::Result<()> {
Ok(inner::hide().await?)
}
mod inner {
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
#[wasm_bindgen(module = "/src/app.js")]
extern "C" {
#[wasm_bindgen(catch)]
pub async fn getName() -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn getTauriVersion() -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn getVersion() -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn hide() -> Result<(), JsValue>;
#[wasm_bindgen(catch)]
pub async fn show() -> Result<(), JsValue>;
}
}