refactor(os): refactor EOL const

pull/427/head
amrbashir 2 years ago
parent 1091d6d6ac
commit c70451b28e
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

@ -9,3 +9,4 @@ The os plugin is recieving a few changes to improve consistency and add new feat
- Added `family()`,`exe_extension()`, and `hostname()` functions and their equivalents for JS.
- Removed `tempdir()` function and its equivalent on JS, use `std::env::temp_dir` instead of `temp_dir` from `tauri::path::PathResolver::temp_dir` and `path.tempDir` on JS.
- Modified `platform()` implementation to return `windows` instead of `win32` and `macos` instead of `darwin` to align with Rust's `std::env::consts::OS`
- `EOL` const in JS has been modified into a function `eol()` fix import issues in frameworks like `next.js`

@ -11,6 +11,9 @@
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
__TAURI_OS__: {
EOL: string;
};
}
}
@ -41,18 +44,16 @@ type Arch =
| "s390x"
| "sparc64";
function isWindows(): boolean {
return navigator.appVersion.includes("Win");
}
/**
* The operating system-specific end-of-line marker.
* Returns the operating system-specific end-of-line marker.
* - `\n` on POSIX
* - `\r\n` on Windows
*
* @since 2.0.0
* */
const EOL = isWindows() ? "\r\n" : "\n";
function eol() {
return window.__TAURI_OS__.EOL;
}
/**
* Returns a string describing the specific operating system in use.
@ -174,7 +175,7 @@ async function hostname(): Promise<string | null> {
}
export {
EOL,
eol,
platform,
family,
version,

@ -91,8 +91,16 @@ pub fn hostname() -> String {
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
let mut init_script = String::new();
init_script.push_str(include_str!("api-iife.js"));
#[cfg(windows)]
let eol = "\r\n";
#[cfg(not(windows))]
let eol = "\n";
init_script.push_str(&format!("window.__TAURI_OS__.EOL = {eol}"));
Builder::new("os")
.js_init_script(include_str!("api-iife.js").to_string())
.js_init_script(init_script)
.invoke_handler(tauri::generate_handler![
commands::platform,
commands::version,

Loading…
Cancel
Save