Replies: 1 comment
-
//!!! core/tauri/src/path/init.js
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
Object.defineProperty(window.__TAURI_INTERNALS__.plugins, 'path', {
value: {
sep: __TEMPLATE_sep__,
delimiter: __TEMPLATE_delimiter__,
audio_dir: __TEMPLATE_audio_dir__,
cache_dir: __TEMPLATE_cache_dir__,
config_dir: __TEMPLATE_config_dir__,
data_dir: __TEMPLATE_data_dir__,
local_data_dir: __TEMPLATE_local_data_dir__,
document_dir: __TEMPLATE_document_dir__,
download_dir: __TEMPLATE_download_dir__,
picture_dir: __TEMPLATE_picture_dir__,
public_dir: __TEMPLATE_public_dir__,
video_dir: __TEMPLATE_video_dir__,
resource_dir: __TEMPLATE_resource_dir__,
temp_dir: __TEMPLATE_temp_dir__,
app_config_dir: __TEMPLATE_app_config_dir__,
app_data_dir: __TEMPLATE_app_data_dir__,
app_local_data_dir: __TEMPLATE_app_local_data_dir__,
app_cache_dir: __TEMPLATE_app_cache_dir__,
app_log_dir: __TEMPLATE_app_log_dir__,
desktop_dir: __TEMPLATE_desktop_dir__,
executable_dir: __TEMPLATE_executable_dir__,
font_dir: __TEMPLATE_font_dir__,
home_dir: __TEMPLATE_home_dir__,
runtime_dir: __TEMPLATE_runtime_dir__,
template_dir: __TEMPLATE_template_dir__
}
}) // !!! core/tauri/src/path/plugin.rs
#[derive(Template)]
#[default_template("./init.js")]
struct InitJavascript<'a> {
sep: &'static str,
delimiter: &'static str,
audio_dir: &'a str,
cache_dir: &'a str,
config_dir: &'a str,
data_dir: &'a str,
local_data_dir: &'a str,
document_dir: &'a str,
download_dir: &'a str,
picture_dir: &'a str,
public_dir: &'a str,
video_dir: &'a str,
resource_dir: &'a str,
temp_dir: &'a str,
app_config_dir: &'a str,
app_data_dir: &'a str,
app_local_data_dir: &'a str,
app_cache_dir: &'a str,
app_log_dir: &'a str,
desktop_dir: &'a str,
executable_dir: &'a str,
font_dir: &'a str,
home_dir: &'a str,
runtime_dir: &'a str,
template_dir: &'a str,
}
impl<'a> InitJavascript<'a> {
fn new() -> Self {
#[cfg(windows)]
let (sep, delimiter) = ("\\", ";");
#[cfg(not(windows))]
let (sep, delimiter) = ("/", ":");
Self {
sep,
delimiter,
audio_dir: dirs::audio_dir().map_or("", |p| p.to_string_lossy()),
cache_dir: dirs::cache_dir().map_or("", |p| p.to_string_lossy()),
config_dir: dirs::config_dir().map_or("", |p| p.to_string_lossy()),
data_dir: dirs::data_dir().map_or("", |p| p.to_string_lossy()),
local_data_dir: dirs::data_local_dir().map_or("", |p| p.to_string_lossy()),
document_dir: dirs::document_dir().map_or("", |p| p.to_string_lossy()),
download_dir: dirs::download_dir().map_or("", |p| p.to_string_lossy()),
picture_dir: dirs::picture_dir().map_or("", |p| p.to_string_lossy()),
public_dir: dirs::public_dir().map_or("", |p| p.to_string_lossy()),
video_dir: dirs::video_dir().map_or("", |p| p.to_string_lossy()),
resource_dir: dirs::resource_dir().map_or("", |p| p.to_string_lossy()),
temp_dir: std::env::temp_dir().to_string_lossy(),
app_config_dir: dirs::config_dir().map_or("", |p| p.join("tauri").to_string_lossy()),
app_data_dir: dirs::data_dir().map_or("", |p| p.join("tauri").to_string_lossy()),
app_local_data_dir: dirs::data_local_dir().map_or("", |p| p.join("tauri").to_string_lossy()),
app_cache_dir: dirs::cache_dir().map_or("", |p| p.join("tauri").to_string_lossy()),
app_log_dir: dirs::data_local_dir().map_or("", |p| p.join("tauri").join("logs").to_string_lossy()),
desktop_dir: dirs::desktop_dir().map_or("", |p| p.to_string_lossy()),
executable_dir: dirs::executable_dir().map_or("", |p| p.to_string_lossy()),
font_dir: dirs::font_dir().map_or("", |p| p.to_string_lossy()),
home_dir: dirs::home_dir().map_or("", |p| p.to_string_lossy()),
runtime_dir: dirs::runtime_dir().map_or("", |p| p.to_string_lossy()),
template_dir: dirs::template_dir().map_or("", |p| p.to_string_lossy()),
}
}
}
/// Initializes the plugin.
pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
let init_js = InitJavascript::new()
.render_default(&Default::default())
// this will never fail with the above sep and delimiter values
.unwrap();
Builder::new("path")
.invoke_handler(crate::generate_handler![
resolve_directory,
resolve,
normalize,
join,
dirname,
extname,
basename,
is_absolute
])
.js_init_script(init_js.to_string())
.setup(|app, _api| {
#[cfg(target_os = "android")]
{
let handle = _api.register_android_plugin("app.tauri", "PathPlugin")?;
app.manage(PathResolver(handle));
}
#[cfg(not(target_os = "android"))]
{
app.manage(PathResolver(app.clone()));
}
Ok(())
})
.build()
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to modify the
path
plug-in so that it can get the path of the system through a synchronous wayHowever, I found a problem in the development, so I can not continue, the reason is to get
taur.conf. json > identifier
beforeBuilder::new("path")
to implementapp_*
series of methods, But I can't get the value ofidentifier
, how do I solve this?Beta Was this translation helpful? Give feedback.
All reactions