From ecc5362c1c8cd2609d4c68eaf5306cd00aace925 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Mon, 2 Sep 2024 16:11:55 +0200 Subject: [PATCH] docs: Add scope handling in file association example (#10864) --- .../file-associations/src-tauri/src/main.rs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/file-associations/src-tauri/src/main.rs b/examples/file-associations/src-tauri/src/main.rs index 68073dff7..1eab17103 100644 --- a/examples/file-associations/src-tauri/src/main.rs +++ b/examples/file-associations/src-tauri/src/main.rs @@ -8,9 +8,30 @@ )] use std::path::PathBuf; -use tauri::AppHandle; +use tauri::{AppHandle, Manager}; fn handle_file_associations(app: AppHandle, files: Vec) { + // -- Scope handling start -- + + // You can remove this block if you only want to know about the paths, but not actually "use" them in the frontend. + + // This requires the `fs` tauri plugin and is required to make the plugin's frontend work: + // use tauri_plugin_fs::FsExt; + // let fs_scope = app.fs_scope(); + + // This is for the `asset:` protocol to work: + let asset_protocol_scope = app.asset_protocol_scope(); + + for file in &files { + // This requires the `fs` plugin: + // let _ = fs_scope.allow_file(file); + + // This is for the `asset:` protocol: + let _ = asset_protocol_scope.allow_file(file); + } + + // -- Scope handling end -- + let files = files .into_iter() .map(|f| {