mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 16:48:30 +02:00
Decouple core Yaak logic from Tauri (#354)
This commit is contained in:
2
crates/yaak-common/src/lib.rs
Normal file
2
crates/yaak-common/src/lib.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod platform;
|
||||
pub mod serde;
|
||||
55
crates/yaak-common/src/platform.rs
Normal file
55
crates/yaak-common/src/platform.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use crate::platform::OperatingSystem::{Linux, MacOS, Unknown, Windows};
|
||||
|
||||
pub enum OperatingSystem {
|
||||
Windows,
|
||||
MacOS,
|
||||
Linux,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub fn get_os() -> OperatingSystem {
|
||||
if cfg!(target_os = "windows") {
|
||||
Windows
|
||||
} else if cfg!(target_os = "macos") {
|
||||
MacOS
|
||||
} else if cfg!(target_os = "linux") {
|
||||
Linux
|
||||
} else {
|
||||
Unknown
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_os_str() -> &'static str {
|
||||
match get_os() {
|
||||
Windows => "windows",
|
||||
MacOS => "macos",
|
||||
Linux => "linux",
|
||||
Unknown => "unknown",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ua_platform() -> &'static str {
|
||||
if cfg!(target_os = "windows") {
|
||||
"Win"
|
||||
} else if cfg!(target_os = "macos") {
|
||||
"Mac"
|
||||
} else if cfg!(target_os = "linux") {
|
||||
"Linux"
|
||||
} else {
|
||||
"Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ua_arch() -> &'static str {
|
||||
if cfg!(target_arch = "x86_64") {
|
||||
"x86_64"
|
||||
} else if cfg!(target_arch = "x86") {
|
||||
"i386"
|
||||
} else if cfg!(target_arch = "arm") {
|
||||
"ARM"
|
||||
} else if cfg!(target_arch = "aarch64") {
|
||||
"ARM64"
|
||||
} else {
|
||||
"Unknown"
|
||||
}
|
||||
}
|
||||
23
crates/yaak-common/src/serde.rs
Normal file
23
crates/yaak-common/src/serde.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub fn get_bool(v: &Value, key: &str, fallback: bool) -> bool {
|
||||
match v.get(key) {
|
||||
None => fallback,
|
||||
Some(v) => v.as_bool().unwrap_or(fallback),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_str<'a>(v: &'a Value, key: &str) -> &'a str {
|
||||
match v.get(key) {
|
||||
None => "",
|
||||
Some(v) => v.as_str().unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_str_map<'a>(v: &'a BTreeMap<String, Value>, key: &str) -> &'a str {
|
||||
match v.get(key) {
|
||||
None => "",
|
||||
Some(v) => v.as_str().unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user