From bc46e11e5a4a8428ee97da2bd2149034910ccf25 Mon Sep 17 00:00:00 2001 From: PiyushXCoder Date: Sun, 7 Jan 2024 15:07:49 +0530 Subject: [PATCH] Embedding ui file in binary --- Cargo.lock | 2 +- Cargo.toml | 12 +++++----- src/config.rs | 49 ---------------------------------------- src/lib.rs | 6 ++--- src/main.rs | 6 +---- ui.glade => src/ui.glade | 0 6 files changed, 11 insertions(+), 64 deletions(-) delete mode 100644 src/config.rs rename ui.glade => src/ui.glade (100%) diff --git a/Cargo.lock b/Cargo.lock index 8b775f1..10da78f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -868,7 +868,7 @@ dependencies = [ [[package]] name = "tarangam" -version = "0.2.0" +version = "0.3.1" dependencies = [ "cairo-rs", "gdk", diff --git a/Cargo.toml b/Cargo.toml index 6ab9a65..0a551da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tarangam" -version = "0.3.0" +version = "0.3.1" authors = ["PiyushXCoder "] license = "GPL-3.0-only" edition = "2018" @@ -14,11 +14,11 @@ keywords = ["plotter", "serial", "serialplotter", "arduino", "gtk"] [dependencies] tokio = { version = "1.5.0", features = [ - "rt", - "rt-multi-thread", - "macros", - "time", - "sync", + "rt", + "rt-multi-thread", + "macros", + "time", + "sync", ] } gtk = "0.15" gdk = "0.15" diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index 13f78db..0000000 --- a/src/config.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::{cell::RefCell, rc::Rc}; - -use gio::prelude::*; -use glib::OptionFlags; - -pub struct Config { - pub ui_file: String, -} - -impl Default for Config { - fn default() -> Self { - Self { - ui_file: std::env::current_exe() - .unwrap() - .parent() - .unwrap() - .join("ui.glade") - .to_str() - .unwrap() - .to_owned(), - } - } -} - -#[allow(dead_code)] -impl Config { - pub fn new(app: >k::Application) -> Rc> { - app.add_main_option( - "ui_file", - glib::Char::from(b'u'), - OptionFlags::NONE, - glib::OptionArg::String, - "Path for ui file", - Some("PATH"), - ); - - let conf = Rc::new(RefCell::new(Self::default())); - - let conf_clone = Rc::clone(&conf); - app.connect_handle_local_options(move |_, dict| { - if let Some(va) = dict.lookup_value("ui_file", None) { - conf_clone.borrow_mut().ui_file = va.str().unwrap_or_default().to_owned(); - }; - -1 - }); - - conf - } -} diff --git a/src/lib.rs b/src/lib.rs index a72cc16..bb82f80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ //! Feel free to see through codes. Application is not written to be used as a library for other app. :) -pub(crate) mod config; pub(crate) mod graph; pub(crate) mod port_util; pub(crate) mod util; @@ -39,9 +38,10 @@ use port_util as putil; use util::Properties; // Building and propsuring GUI -pub fn build_ui(app: >k::Application, ui_file: &str) { +pub fn build_ui(app: >k::Application) { let props = Arc::new(Properties::default()); - let builder = gtk::Builder::from_file(ui_file); + let ui_file = include_str!("ui.glade"); + let builder = gtk::Builder::from_string(ui_file); let win = builder .object::("win") diff --git a/src/main.rs b/src/main.rs index 727cd30..96e907b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,18 +14,14 @@ */ #![windows_subsystem = "windows"] -mod config; - use gio::{prelude::*, ApplicationFlags}; #[tokio::main] async fn main() { let app = gtk::Application::new(Some("sng.tarangm"), ApplicationFlags::default()); - let conf = config::Config::new(&app); - app.connect_activate(move |app| { - tarangam::build_ui(app, &conf.borrow().ui_file); + tarangam::build_ui(app); }); app.run(); } diff --git a/ui.glade b/src/ui.glade similarity index 100% rename from ui.glade rename to src/ui.glade