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

Loading…
Cancel
Save