2024-10-02 02:14:00 +03:00
|
|
|
mod app;
|
2024-09-18 20:33:29 +03:00
|
|
|
|
2024-10-02 02:14:00 +03:00
|
|
|
use app::App;
|
2024-10-02 18:46:08 +03:00
|
|
|
use gtk::glib::{user_config_dir, ExitCode};
|
2024-10-02 20:00:08 +03:00
|
|
|
use sqlite::Connection;
|
2024-10-06 00:43:35 +03:00
|
|
|
use std::{
|
|
|
|
fs::create_dir_all,
|
|
|
|
sync::{Arc, RwLock},
|
|
|
|
};
|
2024-09-21 20:48:12 +03:00
|
|
|
|
2024-10-03 19:46:13 +03:00
|
|
|
const VENDOR: &str = "YGGverse";
|
2024-10-03 20:13:42 +03:00
|
|
|
const APP_ID: &str = "Yoda"; // env!("CARGO_PKG_NAME");
|
|
|
|
const BRANCH: &str = "Rust-GTK4";
|
2024-10-03 19:46:13 +03:00
|
|
|
|
2024-09-30 02:00:14 +03:00
|
|
|
fn main() -> ExitCode {
|
2024-10-02 18:46:08 +03:00
|
|
|
// Init profile path
|
|
|
|
let mut profile_path = user_config_dir();
|
|
|
|
|
2024-10-03 19:46:13 +03:00
|
|
|
profile_path.push(VENDOR);
|
|
|
|
profile_path.push(APP_ID);
|
2024-10-03 20:13:42 +03:00
|
|
|
profile_path.push(BRANCH);
|
2024-10-11 22:35:03 +03:00
|
|
|
profile_path.push(format!(
|
|
|
|
"{}.{}",
|
|
|
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
|
|
|
env!("CARGO_PKG_VERSION_MINOR")
|
|
|
|
)); // @TODO remove after auto-migrate feature implementation
|
2024-10-02 18:46:08 +03:00
|
|
|
|
2024-10-06 00:49:43 +03:00
|
|
|
if let Err(e) = create_dir_all(&profile_path) {
|
|
|
|
panic!("Failed to create profile directory: {e}")
|
2024-10-02 18:46:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init profile database path
|
|
|
|
let mut profile_database_path = profile_path.clone();
|
|
|
|
|
2024-10-03 20:15:07 +03:00
|
|
|
profile_database_path.push("profile.sqlite3");
|
2024-10-02 18:46:08 +03:00
|
|
|
|
|
|
|
// Init database connection
|
2024-10-02 20:00:08 +03:00
|
|
|
let profile_database_connection = match Connection::open(profile_database_path) {
|
2024-10-06 00:43:35 +03:00
|
|
|
Ok(connection) => Arc::new(RwLock::new(connection)),
|
2024-10-06 00:49:43 +03:00
|
|
|
Err(e) => panic!("Failed to connect profile database: {e}"),
|
2024-10-02 18:46:08 +03:00
|
|
|
};
|
|
|
|
|
2024-10-03 15:38:34 +03:00
|
|
|
// Init GTK, start application
|
|
|
|
match gtk::init() {
|
2024-10-04 17:54:25 +03:00
|
|
|
Ok(_) => App::new(profile_database_connection, profile_path).run(),
|
2024-10-03 15:38:34 +03:00
|
|
|
Err(_) => ExitCode::FAILURE,
|
|
|
|
}
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|