CH-J Toolsspráva serverů přes SSH
Menu
Vydané zdroje

CH-J Tools

Procházejte adresáře a soubory konkrétního vydání aplikace.

Stáhnout zdroje ZIP
CH-J / Server Manager 872 souborů
core-20261030T220507Z-61e4558d889f Přidáno: · Sestaveno:
dialogs.rs Přidáno: Datum není evidováno 2,6 KB · 68 řádků
Kód Stáhnout soubor
1//! Native file dialogs owned by the Core (the UI never supplies local paths itself).
3use std::path::PathBuf;
4use tauri::{AppHandle, Manager, Runtime, WebviewWindow};
5use tauri_plugin_dialog::{DialogExt, FileDialogBuilder, FilePath};
7pub struct Filter<'a> {
8 pub name: &'a str,
9 pub extensions: &'a [&'a str],
12fn to_path(file: FilePath) -> Option<PathBuf> {
13 file.into_path().ok()
16fn builder<R: Runtime>(app: &AppHandle<R>, parent: Option<&WebviewWindow<R>>, title: Option<&str>, filters: &[Filter<'_>]) -> FileDialogBuilder<R> {
17 let mut builder = app.dialog().file();
18 if let Some(window) = parent {
19 builder = builder.set_parent(window);
20 }
21 if let Some(title) = title {
22 builder = builder.set_title(title);
23 }
24 for filter in filters {
25 builder = builder.add_filter(filter.name, filter.extensions);
26 }
27 builder
30pub fn main_window<R: Runtime>(app: &AppHandle<R>) -> Option<WebviewWindow<R>> {
31 app.get_webview_window(crate::security::caller::MAIN_LABEL)
34pub async fn pick_file<R: Runtime>(app: &AppHandle<R>, parent: Option<&WebviewWindow<R>>, title: Option<&str>, filters: &[Filter<'_>]) -> Option<PathBuf> {
35 let (tx, rx) = tokio::sync::oneshot::channel();
36 builder(app, parent, title, filters).pick_file(move |file| {
37 let _ = tx.send(file.and_then(to_path));
38 });
39 rx.await.ok().flatten()
42pub async fn pick_files<R: Runtime>(app: &AppHandle<R>, parent: Option<&WebviewWindow<R>>, title: Option<&str>, filters: &[Filter<'_>]) -> Vec<PathBuf> {
43 let (tx, rx) = tokio::sync::oneshot::channel();
44 builder(app, parent, title, filters).pick_files(move |files| {
45 let _ = tx.send(files.unwrap_or_default().into_iter().filter_map(to_path).collect::<Vec<_>>());
46 });
47 rx.await.unwrap_or_default()
50pub async fn pick_folder<R: Runtime>(app: &AppHandle<R>, parent: Option<&WebviewWindow<R>>, title: Option<&str>) -> Option<PathBuf> {
51 let (tx, rx) = tokio::sync::oneshot::channel();
52 builder(app, parent, title, &[]).set_can_create_directories(true).pick_folder(move |folder| {
53 let _ = tx.send(folder.and_then(to_path));
54 });
55 rx.await.ok().flatten()
58pub async fn save_file<R: Runtime>(app: &AppHandle<R>, parent: Option<&WebviewWindow<R>>, title: Option<&str>, suggested: &str, filters: &[Filter<'_>]) -> Option<PathBuf> {
59 let (tx, rx) = tokio::sync::oneshot::channel();
60 let mut builder = builder(app, parent, title, filters);
61 if !suggested.is_empty() {
62 builder = builder.set_file_name(suggested);
63 }
64 builder.save_file(move |file| {
65 let _ = tx.send(file.and_then(to_path));
66 });
67 rx.await.ok().flatten()
SHA-25600aa77f180db125ca992ff210dd123c306ff954e8e6e77d6df7b82dd82da4d7b

CH-J Proprietary Software License 1.14 · Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.

SHA-256 archivu77380d4805485ffa4027fbe7858b5836f197a4aa9d52358a43e2d12d018744df
Soubory