From 29b0a61915da5a344491fe7b0bb846e3170bc3ac Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Sun, 15 Oct 2023 03:21:17 +0300 Subject: [PATCH] little improvements --- Cargo.toml | 6 ++--- src/config_management.rs | 51 ++++++++++++++++++++++++---------------- src/main.rs | 15 +++--------- src/utils.rs | 5 ++++ 4 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 src/utils.rs diff --git a/Cargo.toml b/Cargo.toml index 99fa217..1d6d5fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ gdk = { git = "https://github.com/gtk-rs/gtk4-rs.git", package = "gdk4"} gdk-pixbuf = "0.9.0" gettext-rs = "0.7.0" gtk = { version = "0.4.8", package = "gtk4", features = ["v4_8"] } +gio = { version = "0.15.0" } gtk-sys = "0.15" glib = "0.10.3" rust-ini = "0.16" @@ -21,7 +22,4 @@ subprocess = "0.2.6" dark-light = "1.0.0" async-std = {version = "1.12.0", features = ["attributes"]} gstreamer = "0.20.5" -zbus = "3.12.0" - -[dependencies.gio] -version = "0.15.0" +zbus = "3.12.0" \ No newline at end of file diff --git a/src/config_management.rs b/src/config_management.rs index e48e741..57fdd73 100755 --- a/src/config_management.rs +++ b/src/config_management.rs @@ -1,6 +1,6 @@ +extern crate dirs; extern crate glib; extern crate ini; -extern crate dirs; use glib::get_user_data_dir; use ini::Ini; @@ -29,11 +29,19 @@ pub fn initialize() -> PathBuf { fn default() { set("default", "frame", "60"); set("default", "delay", "0"); - set("default", "folder", + set( + "default", + "folder", String::from("file://") .add( glib::get_user_special_dir(glib::UserDirectory::Videos) - .unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap_or_else(|_| "/".to_string()).as_str())) + .unwrap_or_else(|| { + PathBuf::from( + std::env::var("HOME") + .unwrap_or_else(|_| "/".to_string()) + .as_str(), + ) + }) .to_str() .unwrap(), ) @@ -58,8 +66,12 @@ fn merge_previous_version() -> Option { return None; } - let mut config_string: String = String::from_utf8(std::fs::read(&config_path).unwrap()).unwrap(); - config_string = config_string.replace("Options", "default").replace("True", "1").replace("False", "0"); + let mut config_string: String = + String::from_utf8(std::fs::read(&config_path).unwrap()).unwrap(); + config_string = config_string + .replace("Options", "default") + .replace("True", "1") + .replace("False", "0"); std::fs::write(&config_path, config_string).unwrap(); Some(config_path) } @@ -96,21 +108,20 @@ pub fn set_bool(selection: &str, key: &str, value: bool) -> bool { pub fn folder_icon(folder_chooser_name: Option<&str>) -> &str { let home_folder = dirs::home_dir().unwrap(); - if folder_chooser_name == home_folder.as_path().file_name().unwrap().to_str(){ + if folder_chooser_name == home_folder.as_path().file_name().unwrap().to_str() { "user-home" - } - else { - match folder_chooser_name { - Some("/") => "drive-harddisk", - Some("Desktop") => "user-desktop", - Some("Documents") => "folder-documents", - Some("Downloads") => "folder-download", - Some("Music") => "folder-music", - Some("Pictures") => "folder-pictures", - Some("Public") => "folder-publicshare", - Some("Templates") => "folder-templates", - Some("Videos") => "folder-videos", - _ => "folder", - } + } else { + match folder_chooser_name { + Some("/") => "drive-harddisk", + Some("Desktop") => "user-desktop", + Some("Documents") => "folder-documents", + Some("Downloads") => "folder-download", + Some("Music") => "folder-music", + Some("Pictures") => "folder-pictures", + Some("Public") => "folder-publicshare", + Some("Templates") => "folder-templates", + Some("Videos") => "folder-videos", + _ => "folder", + } } } diff --git a/src/main.rs b/src/main.rs index c9d20cd..165959e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod config_management; mod ffmpeg_interface; mod timer; mod wayland_record; +mod utils; use ffmpeg_interface::{Ffmpeg, ProgressWidget}; use gettextrs::{bindtextdomain, gettext, setlocale, textdomain, LocaleCategory}; @@ -17,6 +18,7 @@ use gtk::{ FileChooserAction, FileChooserNative, Image, Label, MessageDialog, ProgressBar, SpinButton, ToggleButton, Window, }; +use utils::is_wayland; use std::cell::RefCell; use std::ops::Add; use std::path::Path; @@ -35,12 +37,7 @@ async fn main() { } pub fn build_ui(application: &Application) { - // Use "GDK_BACKEND=x11" to make xwininfo work in Wayland by using XWayland - std::env::set_var("GDK_BACKEND", "x11"); - if gtk::init().is_err() { - println!("Failed to initialize GTK."); - return; - } + gtk::init().expect("Failed to initialize GTK."); let ui_src = include_str!("../interfaces/main.ui").to_string(); let builder: Builder = Builder::from_string(ui_src.as_str()); @@ -609,11 +606,5 @@ pub fn build_ui(application: &Application) { gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, ); - fn is_wayland() -> bool { - std::env::var("XDG_SESSION_TYPE") - .unwrap_or_default() - .eq_ignore_ascii_case("wayland") - } - main_window.show(); } diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..0a2b68c --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,5 @@ +pub fn is_wayland() -> bool { + std::env::var("XDG_SESSION_TYPE") + .unwrap_or_default() + .eq_ignore_ascii_case("wayland") +} \ No newline at end of file