diff --git a/Cargo.toml b/Cargo.toml index fd2c548..f80edfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ tauri-sys = { path = ".", features = ["all"] } all-features = true [features] -all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process", "dialog", "notification"] +all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process", "dialog", "os", "notification"] app = ["dep:semver"] clipboard = [] dialog = [] @@ -34,6 +34,7 @@ mocks = [] tauri = ["dep:url"] window = [] process = [] +os = ["dep:semver"] notification = [] [workspace] diff --git a/README.md b/README.md index bbec34e..36d00e2 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ These API bindings are not completely on-par with `@tauri-apps/api` yet, but her - [ ] `http` - [x] `mocks` - [x] `notification` -- [ ] `os` +- [x] `os` - [ ] `path` - [x] `process` - [ ] `shell` diff --git a/examples/test/src-tauri/tauri.conf.json b/examples/test/src-tauri/tauri.conf.json index 63dd763..5d5cc52 100644 --- a/examples/test/src-tauri/tauri.conf.json +++ b/examples/test/src-tauri/tauri.conf.json @@ -58,7 +58,7 @@ "fullscreen": false, "height": 600, "resizable": true, - "title": "tauri-app", + "title": "tauri-sys testing suite", "width": 800 } ] diff --git a/examples/test/src/main.rs b/examples/test/src/main.rs index d2a25d5..5630f5d 100644 --- a/examples/test/src/main.rs +++ b/examples/test/src/main.rs @@ -4,6 +4,7 @@ mod event; mod window; mod dialog; mod notification; +mod os; extern crate console_error_panic_hook; use std::future::Future; @@ -154,6 +155,11 @@ fn main() { InteractiveTest(name="dialog::pick_folder",test=dialog::pick_folder()) InteractiveTest(name="dialog::pick_folders",test=dialog::pick_folders()) InteractiveTest(name="dialog::save",test=dialog::save()) + Test(name="os::arch",test=os::arch()) + Test(name="os::platform",test=os::platform()) + Test(name="os::tempdir",test=os::tempdir()) + Test(name="os::kind",test=os::kind()) + Test(name="os::version",test=os::version()) Test(name="notification::is_permission_granted",test=notification::is_permission_granted()) Test(name="notification::request_permission",test=notification::request_permission()) InteractiveTest(name="notification::show_notification",test=notification::show_notification()) diff --git a/examples/test/src/os.rs b/examples/test/src/os.rs new file mode 100644 index 0000000..f7f31a4 --- /dev/null +++ b/examples/test/src/os.rs @@ -0,0 +1,41 @@ +use tauri_sys::os; + +pub async fn arch() -> anyhow::Result<()> { + let arch = os::arch().await?; + + log::debug!("{:?}", arch); + + Ok(()) +} + +pub async fn platform() -> anyhow::Result<()> { + let platform = os::platform().await?; + + log::debug!("{:?}", platform); + + Ok(()) +} + +pub async fn tempdir() -> anyhow::Result<()> { + let tempdir = os::tempdir().await?; + + log::debug!("{:?}", tempdir); + + Ok(()) +} + +pub async fn kind() -> anyhow::Result<()> { + let kind = os::kind().await?; + + log::debug!("{:?}", kind); + + Ok(()) +} + +pub async fn version() -> anyhow::Result<()> { + let version = os::version().await?; + + log::debug!("{:?}", version); + + Ok(()) +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index ccc3459..465614e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,8 @@ pub mod tauri; pub mod window; #[cfg(feature = "notification")] pub mod notification; +#[cfg(feature = "os")] +pub mod os; #[derive(Debug, thiserror::Error)] pub enum Error { diff --git a/src/os.rs b/src/os.rs new file mode 100644 index 0000000..261a3bd --- /dev/null +++ b/src/os.rs @@ -0,0 +1,111 @@ +use std::path::{PathBuf}; +use semver::Version; +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +pub enum Arch { + #[serde(rename = "x86")] + X86, + #[serde(rename = "x86_64")] + X86_64, + #[serde(rename = "arm")] + Arm, + #[serde(rename = "aarch64")] + Aarch64, + #[serde(rename = "mips")] + Mips, + #[serde(rename = "mips64")] + Mips64, + #[serde(rename = "powerpc")] + Powerpc, + #[serde(rename = "powerpc64")] + Powerpc64, + #[serde(rename = "riscv64")] + Riscv64, + #[serde(rename = "s390x")] + S390x, + #[serde(rename = "sparc64")] + Sparc64 +} + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +pub enum Platform { + #[serde(rename = "linux")] + Linux, + #[serde(rename = "darwin")] + Darwin, + #[serde(rename = "ios")] + Ios, + #[serde(rename = "freebsd")] + Freebsd, + #[serde(rename = "dragonfly")] + Dragonfly, + #[serde(rename = "netbsd")] + Netbsd, + #[serde(rename = "openbsd")] + Openbsd, + #[serde(rename = "solaris")] + Solaris, + #[serde(rename = "android")] + Android, + #[serde(rename = "win32")] + Win32, +} + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +pub enum OsKind { + #[serde(rename = "Linux")] + Linux, + #[serde(rename = "Darwin")] + Darwin, + #[serde(rename = "Windows_NT")] + WindowsNt, +} + +pub async fn arch() -> crate::Result { + let raw = inner::arch().await?; + + Ok(serde_wasm_bindgen::from_value(raw)?) +} + +pub async fn platform() -> crate::Result { + let raw = inner::platform().await?; + + Ok(serde_wasm_bindgen::from_value(raw)?) +} + +pub async fn tempdir() -> crate::Result { + let raw = inner::tempdir().await?; + + Ok(serde_wasm_bindgen::from_value(raw)?) +} + +pub async fn kind() -> crate::Result { + let raw = inner::kind().await?; + + Ok(serde_wasm_bindgen::from_value(raw)?) +} + +pub async fn version() -> crate::Result { + let raw = inner::version().await?; + + Ok(serde_wasm_bindgen::from_value(raw)?) +} + +mod inner { + use wasm_bindgen::prelude::*; + + #[wasm_bindgen(module = "/src/os.js")] + extern "C" { + #[wasm_bindgen(catch)] + pub async fn arch() -> Result; + #[wasm_bindgen(catch)] + pub async fn platform() -> Result; + #[wasm_bindgen(catch)] + pub async fn tempdir() -> Result; + #[wasm_bindgen(catch, js_name = "type")] + pub async fn kind() -> Result; + #[wasm_bindgen(catch)] + pub async fn version() -> Result; + } +}