diff --git a/src/application.rs b/src/application.rs index e30bc4e..3c1d075 100644 --- a/src/application.rs +++ b/src/application.rs @@ -3,9 +3,8 @@ use crate::main_window::PSMainWindow; use crate::ui::dialogs::about::about; use crate::ui::dialogs::preferences::preferences; use crate::ui::dialogs::shortcuts::shortcuts_window; +use crate::utils::path::path_from_bytes; use gtk::{gio, glib, prelude::*, subclass::prelude::*}; -use os_str_bytes::OsStringBytes; -use std::path::PathBuf; const APPLICATION_ID: &str = "dev.andy128k.password-storage"; @@ -154,7 +153,7 @@ impl PSApplication { #[action(name = "open-file")] async fn open_file_by_name(&self, buffer: Vec) { - let filename = PathBuf::assert_from_raw_vec(buffer); + let filename = path_from_bytes(buffer); let win = self.imp().activate_main_window(); win.do_open_file(&filename).await; } diff --git a/src/ui/dashboard.rs b/src/ui/dashboard.rs index e25a114..11be2b0 100644 --- a/src/ui/dashboard.rs +++ b/src/ui/dashboard.rs @@ -1,9 +1,9 @@ use crate::cache::Cache; use crate::primary_accel; +use crate::utils::path::path_as_bytes; use crate::utils::ui::centered; use awesome_gtk::widget::AwesomeWidgetTraverseExt; use gtk::{glib, prelude::*}; -use os_str_bytes::OsStrBytes; use std::path::{Path, PathBuf}; #[derive(Clone)] @@ -100,7 +100,7 @@ pub fn file_row( let row = gtk::ListBoxRow::builder() .action_name("app.open-file") - .action_target(&filename.to_raw_bytes().as_ref().into()) + .action_target(&path_as_bytes(&filename).to_variant()) .css_classes(["frame"]) .child(&grid) .build(); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index d8f7236..38f64e3 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,6 +2,7 @@ pub mod algorithm; pub mod grid_layout; pub mod list_model; pub mod menu_builder; +pub mod path; pub mod string; pub mod style; pub mod typed_list_store; diff --git a/src/utils/path.rs b/src/utils/path.rs new file mode 100644 index 0000000..d77b829 --- /dev/null +++ b/src/utils/path.rs @@ -0,0 +1,10 @@ +use std::ffi::OsString; +use std::path::{Path, PathBuf}; + +pub fn path_as_bytes(path: &Path) -> &[u8] { + path.as_os_str().as_encoded_bytes() +} + +pub fn path_from_bytes(bytes: Vec) -> PathBuf { + PathBuf::from(unsafe { OsString::from_encoded_bytes_unchecked(bytes) }) +}