From 23bb4a122f44ffe1048086c6d65f1dba56193b1f Mon Sep 17 00:00:00 2001 From: Titouan Real <92146833+TitouanReal@users.noreply.github.com> Date: Mon, 26 Aug 2024 02:15:06 +0000 Subject: [PATCH] chore(example): Support special filenames in open-dialog example --- examples/open-dialog/src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/open-dialog/src/main.rs b/examples/open-dialog/src/main.rs index c51d2f6c..5bd2a8bc 100644 --- a/examples/open-dialog/src/main.rs +++ b/examples/open-dialog/src/main.rs @@ -114,17 +114,20 @@ impl cosmic::Application for App { return cosmic::command::future(async move { // Check if its a valid local file path. let path = match url.scheme() { - "file" => url.path(), + "file" => url.to_file_path().unwrap(), other => { return Message::Error(format!("{url} has unknown scheme: {other}")); } }; // Open the file by its path. - let mut file = match tokio::fs::File::open(path).await { + let mut file = match tokio::fs::File::open(&path).await { Ok(file) => file, Err(why) => { - return Message::Error(format!("failed to open {path}: {why}")); + return Message::Error(format!( + "failed to open {}: {why}", + path.display() + )); } }; @@ -132,7 +135,7 @@ impl cosmic::Application for App { contents.clear(); if let Err(why) = file.read_to_string(&mut contents).await { - return Message::Error(format!("failed to read {path}: {why}")); + return Message::Error(format!("failed to read {}: {why}", path.display())); } contents.shrink_to_fit();