mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-28 21:45:00 +03:00
fix(core/path): change sep
and delimiter
to functions (#7160)
* fix(core/path): change `sep` and `delimiter` to functions * fix impl * semicolons * return types * generated * fix init js --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
bfaf624a4c
commit
6d3f3138b9
5
.changes/path-sep-delimter.md
Normal file
5
.changes/path-sep-delimter.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@tauri-apps/api': 'minor:enhance'
|
||||
---
|
||||
|
||||
Changed `sep` and `delimiter` from `path` module into functions to fix import in frameworks like `next.js`
|
File diff suppressed because one or more lines are too long
10
core/tauri/src/path/init.js
Normal file
10
core/tauri/src/path/init.js
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
if (!('path' in window.__TAURI__)) {
|
||||
window.__TAURI__.path = {}
|
||||
}
|
||||
|
||||
window.__TAURI__.path.__sep = __TEMPLATE_sep__
|
||||
window.__TAURI__.path.__delimiter = __TEMPLATE_delimiter__
|
@ -11,6 +11,7 @@ use crate::{
|
||||
|
||||
use serde::{de::Error as DeError, Deserialize, Deserializer};
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
use serialize_to_javascript::{default_template, DefaultTemplate, Template};
|
||||
|
||||
#[cfg(any(path_all, test))]
|
||||
mod commands;
|
||||
@ -331,6 +332,13 @@ fn resolve_path<R: Runtime>(
|
||||
Ok(base_dir_path)
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[default_template("./init.js")]
|
||||
struct InitJavascript {
|
||||
sep: &'static str,
|
||||
delimiter: &'static str,
|
||||
}
|
||||
|
||||
/// Initializes the plugin.
|
||||
pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
#[allow(unused_mut)]
|
||||
@ -350,7 +358,18 @@ pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
]);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
let (sep, delimiter) = ("\\", ";");
|
||||
#[cfg(not(windows))]
|
||||
let (sep, delimiter) = ("/", ":");
|
||||
|
||||
let init_js = InitJavascript { sep, delimiter }
|
||||
.render_default(&Default::default())
|
||||
// this will never fail with the above sep and delimiter values
|
||||
.unwrap();
|
||||
|
||||
builder
|
||||
.js_init_script(init_js.to_string())
|
||||
.setup(|app, _api| {
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
|
428
examples/api/src-tauri/Cargo.lock
generated
428
examples/api/src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -1,19 +0,0 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/** @ignore */
|
||||
|
||||
function isLinux(): boolean {
|
||||
return navigator.appVersion.includes('Linux')
|
||||
}
|
||||
|
||||
function isWindows(): boolean {
|
||||
return navigator.appVersion.includes('Win')
|
||||
}
|
||||
|
||||
function isMacOS(): boolean {
|
||||
return navigator.appVersion.includes('Mac')
|
||||
}
|
||||
|
||||
export { isLinux, isWindows, isMacOS }
|
@ -12,7 +12,6 @@
|
||||
*/
|
||||
|
||||
import { invoke } from './tauri'
|
||||
import { isWindows } from './helpers/os-check'
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
@ -44,6 +43,17 @@ enum BaseDirectory {
|
||||
Template
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__TAURI__: {
|
||||
path: {
|
||||
__sep: string
|
||||
__delimiter: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app's config files.
|
||||
* Resolves to `${configDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
|
||||
@ -541,23 +551,26 @@ async function tempDir(path: string): Promise<string> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the platform-specific path segment separator:
|
||||
* Returns the platform-specific path segment separator:
|
||||
* - `\` on Windows
|
||||
* - `/` on POSIX
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
const sep = isWindows() ? '\\' : '/'
|
||||
function sep(): string {
|
||||
return window.__TAURI__.path.__sep
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the platform-specific path segment delimiter:
|
||||
* Returns the platform-specific path segment delimiter:
|
||||
* - `;` on Windows
|
||||
* - `:` on POSIX
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
const delimiter = isWindows() ? ';' : ':'
|
||||
|
||||
function delimiter(): string {
|
||||
return window.__TAURI__.path.__delimiter
|
||||
}
|
||||
/**
|
||||
* Resolves a sequence of `paths` or `path` segments into an absolute path.
|
||||
* @example
|
||||
|
Loading…
Reference in New Issue
Block a user