From d50d31f7703ddf055caf4937dda3791ca9044f9d Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 23 Feb 2024 21:05:29 +0200 Subject: [PATCH] cookie store --- .changes/dialog-can-create-directories.md | 6 ++++++ plugins/deep-link/src/api-iife.js | 2 +- plugins/dialog/guest-js/index.ts | 4 ++++ plugins/dialog/src/commands.rs | 10 ++++++++++ plugins/dialog/src/desktop.rs | 2 ++ plugins/dialog/src/lib.rs | 8 ++++++++ plugins/http/src/commands.rs | 5 +++++ 7 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .changes/dialog-can-create-directories.md diff --git a/.changes/dialog-can-create-directories.md b/.changes/dialog-can-create-directories.md new file mode 100644 index 0000000000..9b62fbdb63 --- /dev/null +++ b/.changes/dialog-can-create-directories.md @@ -0,0 +1,6 @@ +--- +"dialog": "patch" +"dialog-js": "patch" +--- + +Allow configuring `canCreateDirectories` for open and save dialogs on macOS, if not configured, it will be set to `true` by default. diff --git a/plugins/deep-link/src/api-iife.js b/plugins/deep-link/src/api-iife.js index d46ebd7d19..6a37d74812 100644 --- a/plugins/deep-link/src/api-iife.js +++ b/plugins/deep-link/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_DEEPLINK__=function(e){"use strict";function n(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}async function t(e,n={},t){return window.__TAURI_INTERNALS__.invoke(e,n,t)}var r;async function i(e,r,i){const _="string"==typeof i?.target?{kind:"AnyLabel",label:i.target}:i?.target??{kind:"Any"};return t("plugin:event|listen",{event:e,target:_,handler:n(r)}).then((n=>async()=>async function(e,n){await t("plugin:event|unlisten",{event:e,eventId:n})}(e,n)))}async function _(){return await t("plugin:deep-link|get_current")}return"function"==typeof SuppressedError&&SuppressedError,function(e){e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WEBVIEW_CREATED="tauri://webview-created",e.FILE_DROP="tauri://file-drop",e.FILE_DROP_HOVER="tauri://file-drop-hover",e.FILE_DROP_CANCELLED="tauri://file-drop-cancelled"}(r||(r={})),e.getCurrent=_,e.onOpenUrl=async function(e){const n=await _();return null!=n&&e(n),await i("deep-link://new-url",(n=>e(n.payload)))},e}({});Object.defineProperty(window.__TAURI__,"deepLink",{value:__TAURI_PLUGIN_DEEPLINK__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_DEEPLINK__=function(e){"use strict";function n(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}async function t(e,n={},t){return window.__TAURI_INTERNALS__.invoke(e,n,t)}var r;async function _(e,r,_){const i="string"==typeof _?.target?{kind:"AnyLabel",label:_.target}:_?.target??{kind:"Any"};return t("plugin:event|listen",{event:e,target:i,handler:n(r)}).then((n=>async()=>async function(e,n){await t("plugin:event|unlisten",{event:e,eventId:n})}(e,n)))}async function i(){return await t("plugin:deep-link|get_current")}return"function"==typeof SuppressedError&&SuppressedError,function(e){e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WEBVIEW_CREATED="tauri://webview-created",e.WEBVIEW_FILE_DROP="tauri://file-drop",e.WEBVIEW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WEBVIEW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled"}(r||(r={})),e.getCurrent=i,e.onOpenUrl=async function(e){const n=await i();return null!=n&&e(n),await _("deep-link://new-url",(n=>e(n.payload)))},e}({});Object.defineProperty(window.__TAURI__,"deepLink",{value:__TAURI_PLUGIN_DEEPLINK__})} diff --git a/plugins/dialog/guest-js/index.ts b/plugins/dialog/guest-js/index.ts index 28dc2529c7..5aa440a675 100644 --- a/plugins/dialog/guest-js/index.ts +++ b/plugins/dialog/guest-js/index.ts @@ -55,6 +55,8 @@ interface OpenDialogOptions { * Defines whether subdirectories will be allowed on the scope or not. */ recursive?: boolean; + /** Whether to allow creating directories in the dialog. Enabled by default. **macOS Only** */ + canCreateDirectories?: boolean; } /** @@ -73,6 +75,8 @@ interface SaveDialogOptions { * If it's not an existing directory, the file name will be set to the dialog's file name input and the dialog will be set to the parent folder. */ defaultPath?: string; + /** Whether to allow creating directories in the dialog. Enabled by default. **macOS Only** */ + canCreateDirectories?: boolean; } /** diff --git a/plugins/dialog/src/commands.rs b/plugins/dialog/src/commands.rs index 1a525df0a1..f0dfb092e3 100644 --- a/plugins/dialog/src/commands.rs +++ b/plugins/dialog/src/commands.rs @@ -51,6 +51,8 @@ pub struct OpenDialogOptions { #[serde(default)] #[cfg_attr(mobile, allow(dead_code))] recursive: bool, + /// Whether to allow creating directories in the dialog **macOS Only** + can_create_directories: Option, } /// The options for the save dialog API. @@ -65,6 +67,8 @@ pub struct SaveDialogOptions { filters: Vec, /// The initial path of the dialog. default_path: Option, + /// Whether to allow creating directories in the dialog **macOS Only** + can_create_directories: Option, } fn set_default_path( @@ -105,6 +109,9 @@ pub(crate) async fn open( if let Some(default_path) = options.default_path { dialog_builder = set_default_path(dialog_builder, default_path); } + if let Some(can) = options.can_create_directories { + dialog_builder = dialog_builder.set_can_create_directories(can); + } for filter in options.filters { let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect(); dialog_builder = dialog_builder.add_filter(filter.name, &extensions); @@ -185,6 +192,9 @@ pub(crate) async fn save( if let Some(default_path) = options.default_path { dialog_builder = set_default_path(dialog_builder, default_path); } + if let Some(can) = options.can_create_directories { + dialog_builder = dialog_builder.set_can_create_directories(can); + } for filter in options.filters { let extensions: Vec<&str> = filter.extensions.iter().map(|s| &**s).collect(); dialog_builder = dialog_builder.add_filter(filter.name, &extensions); diff --git a/plugins/dialog/src/desktop.rs b/plugins/dialog/src/desktop.rs index 82bb3fe689..7843f3b5ab 100644 --- a/plugins/dialog/src/desktop.rs +++ b/plugins/dialog/src/desktop.rs @@ -127,6 +127,8 @@ impl From> for FileDialog { builder = builder.set_parent(&WindowHandle(parent)); } + builder = builder.set_can_create_directories(d.can_create_directories.unwrap_or(true)); + builder } } diff --git a/plugins/dialog/src/lib.rs b/plugins/dialog/src/lib.rs index 62563731ba..0e9aa9dbd4 100644 --- a/plugins/dialog/src/lib.rs +++ b/plugins/dialog/src/lib.rs @@ -267,6 +267,7 @@ pub struct FileDialogBuilder { pub(crate) starting_directory: Option, pub(crate) file_name: Option, pub(crate) title: Option, + pub(crate) can_create_directories: Option, #[cfg(desktop)] pub(crate) parent: Option, } @@ -291,6 +292,7 @@ impl FileDialogBuilder { starting_directory: None, file_name: None, title: None, + can_create_directories: None, #[cfg(desktop)] parent: None, } @@ -345,6 +347,12 @@ impl FileDialogBuilder { self } + /// Set whether it should be possible to create new directories in the dialog. Enabled by default. **macOS only**. + pub fn set_can_create_directories(mut self, can: bool) -> Self { + self.can_create_directories.replace(can); + self + } + /// Shows the dialog to select a single file. /// This is not a blocking operation, /// and should be used when running on the main thread to avoid deadlocks with the event loop. diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index d4b2469bf3..ad616f583c 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -190,6 +190,11 @@ pub async fn fetch( builder = attach_proxy(proxy_config, builder)?; } + #[cfg(feature = "cookies")] + { + builder = builder.cookie_store(true); + } + let mut request = builder.build()?.request(method.clone(), url); for (name, value) in &headers {