mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-20 21:20:42 +02:00
refactor(os)!: make platform, arch, type, family, version and exe_extension functions sync (#1353)
closes #1351
This commit is contained in:
@@ -2,36 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#[tauri::command]
|
||||
pub fn platform() -> &'static str {
|
||||
crate::platform()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn version() -> String {
|
||||
crate::version().to_string()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn os_type() -> String {
|
||||
crate::type_().to_string()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn family() -> &'static str {
|
||||
crate::family()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn arch() -> &'static str {
|
||||
crate::arch()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn exe_extension() -> &'static str {
|
||||
crate::exe_extension()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn locale() -> Option<String> {
|
||||
crate::locale()
|
||||
|
||||
@@ -6,5 +6,11 @@
|
||||
Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
|
||||
value: {
|
||||
eol: __TEMPLATE_eol__,
|
||||
os_type: __TEMPLATE_os_type__,
|
||||
platform: __TEMPLATE_platform__,
|
||||
family: __TEMPLATE_family__,
|
||||
version: __TEMPLATE_version__,
|
||||
arch: __TEMPLATE_arch__,
|
||||
exe_extension: __TEMPLATE_exe_extension__,
|
||||
},
|
||||
});
|
||||
|
||||
+28
-16
@@ -102,30 +102,42 @@ pub fn hostname() -> String {
|
||||
|
||||
#[derive(Template)]
|
||||
#[default_template("./init.js")]
|
||||
struct InitJavascript {
|
||||
struct InitJavascript<'a> {
|
||||
eol: &'static str,
|
||||
os_type: String,
|
||||
platform: &'a str,
|
||||
family: &'a str,
|
||||
version: String,
|
||||
arch: &'a str,
|
||||
exe_extension: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> InitJavascript<'a> {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
#[cfg(windows)]
|
||||
eol: "\r\n",
|
||||
#[cfg(not(windows))]
|
||||
eol: "\n",
|
||||
os_type: crate::type_().to_string(),
|
||||
platform: crate::platform(),
|
||||
family: crate::family(),
|
||||
version: crate::version().to_string(),
|
||||
arch: crate::arch(),
|
||||
exe_extension: crate::exe_extension(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
let init_js = InitJavascript {
|
||||
#[cfg(windows)]
|
||||
eol: "\r\n",
|
||||
#[cfg(not(windows))]
|
||||
eol: "\n",
|
||||
}
|
||||
.render_default(&Default::default())
|
||||
// this will never fail with the above global_os_api eol values
|
||||
.unwrap();
|
||||
let init_js = InitJavascript::new()
|
||||
.render_default(&Default::default())
|
||||
// this will never fail with the above global_os_api values
|
||||
.unwrap();
|
||||
|
||||
Builder::new("os")
|
||||
.js_init_script(init_js.to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::platform,
|
||||
commands::version,
|
||||
commands::os_type,
|
||||
commands::family,
|
||||
commands::arch,
|
||||
commands::exe_extension,
|
||||
commands::locale,
|
||||
commands::hostname
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user