|
|
|
@ -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,8 +32,7 @@ impl Display for Kind {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<R: Runtime> OperatingSystem<R> {
|
|
|
|
|
pub fn platform(&self) -> &'static str {
|
|
|
|
|
pub fn platform() -> &'static str {
|
|
|
|
|
match std::env::consts::OS {
|
|
|
|
|
"windows" => "win32",
|
|
|
|
|
"macos" => "darwin",
|
|
|
|
@ -43,11 +40,11 @@ impl<R: Runtime> OperatingSystem<R> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn version(&self) -> Version {
|
|
|
|
|
pub fn version() -> Version {
|
|
|
|
|
os_info::get().version().clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn kind(&self) -> Kind {
|
|
|
|
|
pub fn kind() -> Kind {
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
return Kind::Linux;
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
@ -60,24 +57,13 @@ impl<R: Runtime> OperatingSystem<R> {
|
|
|
|
|
return Kind::Android;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn arch(&self) -> &'static str {
|
|
|
|
|
pub fn arch() -> &'static str {
|
|
|
|
|
std::env::consts::ARCH
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn tempdir(&self) -> PathBuf {
|
|
|
|
|
pub fn tempdir() -> PathBuf {
|
|
|
|
|
std::env::temp_dir()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait OperatingSystemExt<R: Runtime> {
|
|
|
|
|
fn os(&self) -> &OperatingSystem<R>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<R: Runtime, T: Manager<R>> OperatingSystemExt<R> for T {
|
|
|
|
|
fn os(&self) -> &OperatingSystem<R> {
|
|
|
|
|
self.state::<OperatingSystem<R>>().inner()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
|
|
|
Builder::new("os")
|
|
|
|
@ -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()
|
|
|
|
|
}
|
|
|
|
|