mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): validate dialog default_path (it must exist) (#1599)
This commit is contained in:
committed by
GitHub
parent
aa7e2738cc
commit
cfa74ebf68
5
.changes/dialog-default-path-validation.md
Normal file
5
.changes/dialog-default-path-validation.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Validate dialog option `defaultPath` - it must exists.
|
||||
@@ -144,6 +144,9 @@ fn set_default_path(
|
||||
pub fn open(options: OpenDialogOptions) -> crate::Result<InvokeResponse> {
|
||||
let mut dialog_builder = FileDialogBuilder::new();
|
||||
if let Some(default_path) = options.default_path {
|
||||
if !default_path.exists() {
|
||||
return Err(crate::Error::DialogDefaultPathNotExists(default_path));
|
||||
}
|
||||
dialog_builder = set_default_path(dialog_builder, default_path);
|
||||
}
|
||||
for filter in options.filters {
|
||||
@@ -165,6 +168,9 @@ pub fn open(options: OpenDialogOptions) -> crate::Result<InvokeResponse> {
|
||||
pub fn save(options: SaveDialogOptions) -> crate::Result<InvokeResponse> {
|
||||
let mut dialog_builder = FileDialogBuilder::new();
|
||||
if let Some(default_path) = options.default_path {
|
||||
if !default_path.exists() {
|
||||
return Err(crate::Error::DialogDefaultPathNotExists(default_path));
|
||||
}
|
||||
dialog_builder = set_default_path(dialog_builder, default_path);
|
||||
}
|
||||
for filter in options.filters {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Runtime errors that can happen inside a Tauri application.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
@@ -60,6 +62,9 @@ pub enum Error {
|
||||
/// Error initializing plugin.
|
||||
#[error("failed to initialize plugin `{0}`: {1}")]
|
||||
PluginInitialization(String, String),
|
||||
/// `default_path` provided to dialog API doesn't exist.
|
||||
#[error("failed to setup dialog: provided default path `{0}` doesn't exist")]
|
||||
DialogDefaultPathNotExists(PathBuf),
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
|
||||
Reference in New Issue
Block a user