mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-29 20:44:25 +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 browser::Browser;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use crate::{action::Browser as BrowserAction, Profile};
|
use crate::{action::Browser as BrowserAction, profile::Profile};
|
||||||
use adw::Application;
|
use adw::Application;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
@ -25,14 +25,16 @@ pub struct App {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(profile: Rc<Profile>) -> Self {
|
pub fn new() -> Self {
|
||||||
|
// Init profile
|
||||||
|
let profile = Rc::new(Profile::new());
|
||||||
|
|
||||||
// Init actions
|
// Init actions
|
||||||
let browser_action = Rc::new(BrowserAction::new());
|
let browser_action = Rc::new(BrowserAction::new());
|
||||||
|
|
||||||
// Init defaults
|
// @TODO
|
||||||
let default_state = (-1).to_variant();
|
let default_state = (-1).to_variant();
|
||||||
|
|
||||||
// Init actions
|
|
||||||
let action_page_new = SimpleAction::new(&uuid_string_random(), None);
|
let action_page_new = SimpleAction::new(&uuid_string_random(), None);
|
||||||
let action_page_close =
|
let action_page_close =
|
||||||
SimpleAction::new_stateful(&uuid_string_random(), None, &default_state);
|
SimpleAction::new_stateful(&uuid_string_random(), None, &default_state);
|
||||||
|
@ -8,7 +8,7 @@ use database::Database;
|
|||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
|
|
||||||
use crate::{action::Browser as BrowserAction, Profile};
|
use crate::{action::Browser as BrowserAction, profile::Profile};
|
||||||
use adw::ApplicationWindow;
|
use adw::ApplicationWindow;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{Cancellable, File, SimpleAction},
|
gio::{Cancellable, File, SimpleAction},
|
||||||
|
19
src/main.rs
19
src/main.rs
@ -2,29 +2,12 @@ mod action;
|
|||||||
mod app;
|
mod app;
|
||||||
mod profile;
|
mod profile;
|
||||||
|
|
||||||
use crate::profile::Profile;
|
|
||||||
use app::App;
|
use app::App;
|
||||||
use gtk::glib::ExitCode;
|
use gtk::glib::ExitCode;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
const VENDOR: &str = "YGGverse";
|
|
||||||
const APP_ID: &str = "Yoda";
|
|
||||||
const BRANCH: &str = "master";
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
match gtk::init() {
|
match gtk::init() {
|
||||||
Ok(_) => App::new(Rc::new(Profile::new(
|
Ok(_) => App::new().run(),
|
||||||
VENDOR,
|
|
||||||
APP_ID,
|
|
||||||
BRANCH,
|
|
||||||
format!(
|
|
||||||
"{}.{}",
|
|
||||||
env!("CARGO_PKG_VERSION_MAJOR"),
|
|
||||||
env!("CARGO_PKG_VERSION_MINOR")
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
)))
|
|
||||||
.run(),
|
|
||||||
Err(_) => ExitCode::FAILURE,
|
Err(_) => ExitCode::FAILURE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,10 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const VENDOR: &str = "YGGverse";
|
||||||
|
const APP_ID: &str = "Yoda";
|
||||||
|
const BRANCH: &str = "master";
|
||||||
|
|
||||||
const DB_NAME: &str = "profile.sqlite3";
|
const DB_NAME: &str = "profile.sqlite3";
|
||||||
|
|
||||||
pub struct Profile {
|
pub struct Profile {
|
||||||
@ -17,14 +21,18 @@ pub struct Profile {
|
|||||||
impl Profile {
|
impl Profile {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
pub fn new(vendor: &str, app_id: &str, branch: &str, version: &str) -> Self {
|
pub fn new() -> Self {
|
||||||
// Init profile path
|
// Init profile path
|
||||||
let mut config_path = user_config_dir();
|
let mut config_path = user_config_dir();
|
||||||
|
|
||||||
config_path.push(vendor);
|
config_path.push(VENDOR);
|
||||||
config_path.push(app_id);
|
config_path.push(APP_ID);
|
||||||
config_path.push(branch);
|
config_path.push(BRANCH);
|
||||||
config_path.push(version); // @TODO remove after auto-migrate feature implementation
|
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) {
|
if let Err(e) = create_dir_all(&config_path) {
|
||||||
panic!("Failed to create profile directory: {e}")
|
panic!("Failed to create profile directory: {e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user