Update plugins/os/src/lib.rs

Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
pull/346/head
Lucas Fernandes Nogueira 2 years ago committed by GitHub
parent a28f82bf6b
commit 914f501430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,8 +12,6 @@ mod error;
pub use error::Error;
type Result<T> = std::result::Result<T, Error>;
pub struct OperatingSystem<R: Runtime>(AppHandle<R>);
pub enum Kind {
Linux,
Windows,
@ -34,49 +32,37 @@ impl Display for Kind {
}
}
impl<R: Runtime> OperatingSystem<R> {
pub fn platform(&self) -> &'static str {
match std::env::consts::OS {
"windows" => "win32",
"macos" => "darwin",
_ => std::env::consts::OS,
}
}
pub fn version(&self) -> Version {
os_info::get().version().clone()
}
pub fn kind(&self) -> Kind {
#[cfg(target_os = "linux")]
return Kind::Linux;
#[cfg(target_os = "windows")]
return Kind::Windows;
#[cfg(target_os = "macos")]
return Kind::Darwin;
#[cfg(target_os = "ios")]
return Kind::IOS;
#[cfg(target_os = "android")]
return Kind::Android;
pub fn platform() -> &'static str {
match std::env::consts::OS {
"windows" => "win32",
"macos" => "darwin",
_ => std::env::consts::OS,
}
}
pub fn arch(&self) -> &'static str {
std::env::consts::ARCH
}
pub fn version() -> Version {
os_info::get().version().clone()
}
pub fn tempdir(&self) -> PathBuf {
std::env::temp_dir()
}
pub fn kind() -> Kind {
#[cfg(target_os = "linux")]
return Kind::Linux;
#[cfg(target_os = "windows")]
return Kind::Windows;
#[cfg(target_os = "macos")]
return Kind::Darwin;
#[cfg(target_os = "ios")]
return Kind::IOS;
#[cfg(target_os = "android")]
return Kind::Android;
}
pub trait OperatingSystemExt<R: Runtime> {
fn os(&self) -> &OperatingSystem<R>;
pub fn arch() -> &'static str {
std::env::consts::ARCH
}
impl<R: Runtime, T: Manager<R>> OperatingSystemExt<R> for T {
fn os(&self) -> &OperatingSystem<R> {
self.state::<OperatingSystem<R>>().inner()
}
pub fn tempdir() -> PathBuf {
std::env::temp_dir()
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
@ -88,9 +74,5 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
commands::arch,
commands::tempdir
])
.setup(|app, _api| {
app.manage(OperatingSystem(app.clone()));
Ok(())
})
.build()
}

Loading…
Cancel
Save