mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-28 20:14:13 +00:00
init profile in constructor
This commit is contained in:
parent
25b63c0e02
commit
a0201ea83b
10
src/app.rs
10
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<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);
|
||||
|
@ -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
19
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,
|
||||
}
|
||||
}
|
||||
|
@ -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}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user