feat: add os module
This commit is contained in:
parent
45bd3650ea
commit
822910bb38
7 changed files with 164 additions and 3 deletions
|
@ -24,7 +24,7 @@ tauri-sys = { path = ".", features = ["all"] }
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process", "dialog"]
|
all = ["app", "clipboard", "event", "mocks", "tauri", "window", "process", "dialog", "os"]
|
||||||
app = ["dep:semver"]
|
app = ["dep:semver"]
|
||||||
clipboard = []
|
clipboard = []
|
||||||
dialog = []
|
dialog = []
|
||||||
|
@ -33,6 +33,7 @@ mocks = []
|
||||||
tauri = ["dep:url"]
|
tauri = ["dep:url"]
|
||||||
window = []
|
window = []
|
||||||
process = []
|
process = []
|
||||||
|
os = ["dep:semver"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["examples/test", "examples/test/src-tauri"]
|
members = ["examples/test", "examples/test/src-tauri"]
|
||||||
|
|
|
@ -62,7 +62,7 @@ These API bindings are not completely on-par with `@tauri-apps/api` yet, but her
|
||||||
- [ ] `http`
|
- [ ] `http`
|
||||||
- [x] `mocks`
|
- [x] `mocks`
|
||||||
- [ ] `notification`
|
- [ ] `notification`
|
||||||
- [ ] `os`
|
- [x] `os`
|
||||||
- [ ] `path`
|
- [ ] `path`
|
||||||
- [ ] `process`
|
- [ ] `process`
|
||||||
- [ ] `shell`
|
- [ ] `shell`
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
"fullscreen": false,
|
"fullscreen": false,
|
||||||
"height": 600,
|
"height": 600,
|
||||||
"resizable": true,
|
"resizable": true,
|
||||||
"title": "tauri-app",
|
"title": "tauri-sys testing suite",
|
||||||
"width": 800
|
"width": 800
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,6 +3,7 @@ mod clipboard;
|
||||||
mod event;
|
mod event;
|
||||||
mod window;
|
mod window;
|
||||||
mod dialog;
|
mod dialog;
|
||||||
|
mod os;
|
||||||
|
|
||||||
extern crate console_error_panic_hook;
|
extern crate console_error_panic_hook;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
@ -153,6 +154,11 @@ fn main() {
|
||||||
InteractiveTest(name="dialog::pick_folder",test=dialog::pick_folder())
|
InteractiveTest(name="dialog::pick_folder",test=dialog::pick_folder())
|
||||||
InteractiveTest(name="dialog::pick_folders",test=dialog::pick_folders())
|
InteractiveTest(name="dialog::pick_folders",test=dialog::pick_folders())
|
||||||
InteractiveTest(name="dialog::save",test=dialog::save())
|
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())
|
// Test(name="window::WebviewWindow::new",test=window::create_window())
|
||||||
|
|
||||||
|
|
41
examples/test/src/os.rs
Normal file
41
examples/test/src/os.rs
Normal 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(())
|
||||||
|
}
|
|
@ -16,6 +16,8 @@ pub mod process;
|
||||||
pub mod tauri;
|
pub mod tauri;
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
#[cfg(feature = "os")]
|
||||||
|
pub mod os;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
111
src/os.rs
Normal file
111
src/os.rs
Normal 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>;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue