Merge pull request #8 from JonasKruckenberg/feat/os

feat: add os module
This commit is contained in:
Jonas Kruckenberg 2022-11-15 16:38:18 +01:00 committed by GitHub
commit ebb42a700b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 164 additions and 3 deletions

View file

@ -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"]

View file

@ -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`

View file

@ -58,7 +58,7 @@
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "tauri-app",
"title": "tauri-sys testing suite",
"width": 800
}
]

View file

@ -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())

41
examples/test/src/os.rs Normal file
View file

@ -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(())
}

View file

@ -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 {

111
src/os.rs Normal file
View file

@ -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<Arch> {
let raw = inner::arch().await?;
Ok(serde_wasm_bindgen::from_value(raw)?)
}
pub async fn platform() -> crate::Result<Platform> {
let raw = inner::platform().await?;
Ok(serde_wasm_bindgen::from_value(raw)?)
}
pub async fn tempdir() -> crate::Result<PathBuf> {
let raw = inner::tempdir().await?;
Ok(serde_wasm_bindgen::from_value(raw)?)
}
pub async fn kind() -> crate::Result<OsKind> {
let raw = inner::kind().await?;
Ok(serde_wasm_bindgen::from_value(raw)?)
}
pub async fn version() -> crate::Result<Version> {
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<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn platform() -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn tempdir() -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch, js_name = "type")]
pub async fn kind() -> Result<JsValue, JsValue>;
#[wasm_bindgen(catch)]
pub async fn version() -> Result<JsValue, JsValue>;
}
}