CH-J ToolsZarządzanie serwerem przez SSH
Menu
Opublikowane źródło

CH-J Tools

Przeglądaj katalogi i pliki dla konkretnego wydania aplikacji.

Pobierz źródło ZIP
CH-J / Server Manager 1704 pliki
0.1.2-beta Dodano: · Built:
dialogs.rs Dodano: Data niezanotowana 2,8 KB · 73 linie
Kod Pobierz plik PDF
1//! Native file dialogs owned by the Core (the UI never supplies local paths itself).
3use std::path::PathBuf;
4use tauri::{AppHandle, Manager, Runtime, Window};
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<&Window<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<Window<R>> {
31 app.get_window(crate::security::caller::MAIN_LABEL)
34pub async fn pick_file<R: Runtime>(app: &AppHandle<R>, parent: Option<&Window<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<&Window<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<&Window<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<&Window<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()
70/// The window that currently holds a WebView; a module can be in the main window or in its own.
71pub fn host_window<R: Runtime>(app: &AppHandle<R>, webview_label: &str) -> Option<Window<R>> {
72 app.get_webview(webview_label).map(|webview| webview.window())
SHA-2563e5d632f08943a0d4a8f28bb25c982f7ae3cb718ab0245e3f58d1a4e2b2c18cb

CH-J Proprietary Software License 1.14 · Źródło jest dostarczane pod CH-J Proprietary Software License 1.14. Jego dostępność nie zmienia warunków licencji ani nie przyznaje dodatkowych praw.

SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Pliki