mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
collect profile features into one shared struct
This commit is contained in:
parent
ec7a668cd9
commit
25b63c0e02
5 changed files with 111 additions and 62 deletions
50
src/main.rs
50
src/main.rs
|
|
@ -1,46 +1,30 @@
|
|||
mod action;
|
||||
mod app;
|
||||
mod profile;
|
||||
|
||||
use crate::profile::Profile;
|
||||
use app::App;
|
||||
use gtk::glib::{user_config_dir, ExitCode};
|
||||
use sqlite::Connection;
|
||||
use std::{fs::create_dir_all, rc::Rc, sync::RwLock};
|
||||
use gtk::glib::ExitCode;
|
||||
use std::rc::Rc;
|
||||
|
||||
const VENDOR: &str = "YGGverse";
|
||||
const APP_ID: &str = "Yoda"; // env!("CARGO_PKG_NAME");
|
||||
const APP_ID: &str = "Yoda";
|
||||
const BRANCH: &str = "master";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
// Init profile path
|
||||
let mut profile_path = user_config_dir();
|
||||
|
||||
profile_path.push(VENDOR);
|
||||
profile_path.push(APP_ID);
|
||||
profile_path.push(BRANCH);
|
||||
profile_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(&profile_path) {
|
||||
panic!("Failed to create profile directory: {e}")
|
||||
}
|
||||
|
||||
// Init profile database path
|
||||
let mut profile_database_path = profile_path.clone();
|
||||
|
||||
profile_database_path.push("profile.sqlite3");
|
||||
|
||||
// Init database connection
|
||||
let profile_database_connection = match Connection::open(profile_database_path) {
|
||||
Ok(connection) => Rc::new(RwLock::new(connection)),
|
||||
Err(e) => panic!("Failed to connect profile database: {e}"),
|
||||
};
|
||||
|
||||
// Init GTK, start application
|
||||
match gtk::init() {
|
||||
Ok(_) => App::new(profile_database_connection, profile_path).run(), // @TODO common struct for profile data
|
||||
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(),
|
||||
Err(_) => ExitCode::FAILURE,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue