Skip to content

Commit

Permalink
Replace crate os_str_bytes with libstd (bump MSRV to 1.74)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Nov 18, 2023
1 parent 17f7aed commit 6f08c67
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -154,7 +153,7 @@ impl PSApplication {

#[action(name = "open-file")]
async fn open_file_by_name(&self, buffer: Vec<u8>) {
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/dashboard.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/utils/path.rs
Original file line number Diff line number Diff line change
@@ -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<u8>) -> PathBuf {
PathBuf::from(unsafe { OsString::from_encoded_bytes_unchecked(bytes) })
}

0 comments on commit 6f08c67

Please sign in to comment.