diff --git a/Cargo.toml b/Cargo.toml index c496dd2..55494f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ tauri-sys = { path = ".", features = ["all"] } all-features = true [features] -all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process", "dialog"] +all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process", "dialog", "os"] app = ["dep:semver"] clipboard = [] dialog = [] @@ -33,6 +33,7 @@ mocks = [] tauri = ["dep:url"] window = [] process = [] +os = ["dep:semver"] [workspace] members = ["examples/test", "examples/test/src-tauri"] diff --git a/README.md b/README.md index aa9c715..086683a 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` - [ ] `notification` -- [ ] `os` +- [x] `os` - [ ] `path` - [ ] `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 e4ff326..194441e 100644 --- a/examples/test/src/main.rs +++ b/examples/test/src/main.rs @@ -3,6 +3,7 @@ mod clipboard; mod event; mod window; mod dialog; +mod os; extern crate console_error_panic_hook; use std::future::Future; @@ -153,6 +154,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="window::WebviewWindow::new",test=window::create_window()) 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 64c7a40..0b52609 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,8 @@ pub mod process; pub mod tauri; #[cfg(feature = "window")] pub mod window; +#[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; + } +}