Browse Source

init profile in constructor

master
yggverse 4 weeks ago
parent
commit
a0201ea83b
  1. 10
      src/app.rs
  2. 2
      src/app/browser.rs
  3. 19
      src/main.rs
  4. 18
      src/profile.rs

10
src/app.rs

@ -4,7 +4,7 @@ mod database; @@ -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 { @@ -25,14 +25,16 @@ pub struct App {
impl App {
// Construct
pub fn new(profile: Rc<Profile>) -> 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);

2
src/app/browser.rs

@ -8,7 +8,7 @@ use database::Database; @@ -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},

19
src/main.rs

@ -2,29 +2,12 @@ mod action; @@ -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,
}
}

18
src/profile.rs

@ -7,6 +7,10 @@ use std::{ @@ -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 { @@ -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}")

Loading…
Cancel
Save