mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-10 14:13:55 +02:00
refactor(os): refactor EOL const (#427)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
+21
-1
@@ -5,6 +5,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
pub use os_info::Version;
|
||||
use serialize_to_javascript::{default_template, DefaultTemplate, Template};
|
||||
use tauri::{
|
||||
plugin::{Builder, TauriPlugin},
|
||||
Runtime,
|
||||
@@ -90,9 +91,28 @@ pub fn hostname() -> String {
|
||||
gethostname::gethostname().to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[default_template("./init.js")]
|
||||
struct InitJavascript {
|
||||
#[raw]
|
||||
global_os_api: &'static str,
|
||||
eol: &'static str,
|
||||
}
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
let init_js = InitJavascript {
|
||||
global_os_api: include_str!("api-iife.js"),
|
||||
#[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();
|
||||
|
||||
Builder::new("os")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
.js_init_script(init_js.to_string())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::platform,
|
||||
commands::version,
|
||||
|
||||
Reference in New Issue
Block a user