From a0201ea83ba054ad01de17f1f54d97c33481bc6d Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 8 Nov 2024 08:43:02 +0200 Subject: [PATCH] init profile in constructor --- src/app.rs | 10 ++++++---- src/app/browser.rs | 2 +- src/main.rs | 19 +------------------ src/profile.rs | 18 +++++++++++++----- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/app.rs b/src/app.rs index d034c858..21801b51 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,7 +4,7 @@ mod database; use browser::Browser; use database::Database; -use crate::{action::Browser as BrowserAction, Profile}; +use crate::{action::Browser as BrowserAction, profile::Profile}; use adw::Application; use gtk::{ gio::SimpleAction, @@ -25,14 +25,16 @@ pub struct App { impl App { // Construct - pub fn new(profile: Rc) -> Self { + pub fn new() -> Self { + // Init profile + let profile = Rc::new(Profile::new()); + // Init actions let browser_action = Rc::new(BrowserAction::new()); - // Init defaults + // @TODO let default_state = (-1).to_variant(); - // Init actions let action_page_new = SimpleAction::new(&uuid_string_random(), None); let action_page_close = SimpleAction::new_stateful(&uuid_string_random(), None, &default_state); diff --git a/src/app/browser.rs b/src/app/browser.rs index e0929ba3..3260778a 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -8,7 +8,7 @@ use database::Database; use widget::Widget; use window::Window; -use crate::{action::Browser as BrowserAction, Profile}; +use crate::{action::Browser as BrowserAction, profile::Profile}; use adw::ApplicationWindow; use gtk::{ gio::{Cancellable, File, SimpleAction}, diff --git a/src/main.rs b/src/main.rs index 39eebd12..d8267714 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,29 +2,12 @@ mod action; mod app; mod profile; -use crate::profile::Profile; use app::App; use gtk::glib::ExitCode; -use std::rc::Rc; - -const VENDOR: &str = "YGGverse"; -const APP_ID: &str = "Yoda"; -const BRANCH: &str = "master"; fn main() -> ExitCode { match gtk::init() { - Ok(_) => App::new(Rc::new(Profile::new( - VENDOR, - APP_ID, - BRANCH, - format!( - "{}.{}", - env!("CARGO_PKG_VERSION_MAJOR"), - env!("CARGO_PKG_VERSION_MINOR") - ) - .as_str(), - ))) - .run(), + Ok(_) => App::new().run(), Err(_) => ExitCode::FAILURE, } } diff --git a/src/profile.rs b/src/profile.rs index 9a4a15ec..4ce8524e 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -7,6 +7,10 @@ use std::{ path::{Path, PathBuf}, }; +const VENDOR: &str = "YGGverse"; +const APP_ID: &str = "Yoda"; +const BRANCH: &str = "master"; + const DB_NAME: &str = "profile.sqlite3"; pub struct Profile { @@ -17,14 +21,18 @@ pub struct Profile { impl Profile { // Constructors - pub fn new(vendor: &str, app_id: &str, branch: &str, version: &str) -> Self { + pub fn new() -> Self { // Init profile path let mut config_path = user_config_dir(); - config_path.push(vendor); - config_path.push(app_id); - config_path.push(branch); - config_path.push(version); // @TODO remove after auto-migrate feature implementation + config_path.push(VENDOR); + config_path.push(APP_ID); + config_path.push(BRANCH); + config_path.push(format!( + "{}.{}", + env!("CARGO_PKG_VERSION_MAJOR"), + env!("CARGO_PKG_VERSION_MINOR") + )); // @TODO remove after auto-migrate feature implementation if let Err(e) = create_dir_all(&config_path) { panic!("Failed to create profile directory: {e}")