2023-01-18 16:37:53 +00:00
|
|
|
use relm4::prelude::*;
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2023-01-18 16:37:53 +00:00
|
|
|
use anime_launcher_sdk::config;
|
2023-01-29 13:11:13 +00:00
|
|
|
use anime_launcher_sdk::anime_game_core::prelude::*;
|
|
|
|
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
|
2022-07-27 15:37:52 +00:00
|
|
|
|
2023-02-11 10:34:39 +00:00
|
|
|
use tracing_subscriber::prelude::*;
|
2023-02-23 12:14:06 +00:00
|
|
|
use tracing_subscriber::filter::*;
|
2023-02-11 10:34:39 +00:00
|
|
|
|
2023-02-21 15:32:57 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2023-01-18 16:37:53 +00:00
|
|
|
pub mod i18n;
|
2022-06-29 07:11:19 +00:00
|
|
|
pub mod ui;
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2023-01-22 12:37:19 +00:00
|
|
|
mod prettify_bytes;
|
|
|
|
|
|
|
|
pub use prettify_bytes::prettify_bytes;
|
|
|
|
|
2023-01-19 11:45:03 +00:00
|
|
|
pub const APP_ID: &str = "moe.launcher.an-anime-game-launcher-gtk";
|
|
|
|
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
2023-02-04 14:13:09 +00:00
|
|
|
pub const APP_DEBUG: bool = cfg!(debug_assertions);
|
2023-01-19 11:45:03 +00:00
|
|
|
|
2023-01-29 13:11:13 +00:00
|
|
|
/// Sets to `true` when the `App` component is ready (fully initialized)
|
|
|
|
pub static mut READY: bool = false;
|
|
|
|
|
|
|
|
// TODO: get rid of using this function in all the components' events
|
|
|
|
// e.g. by converting preferences pages into Relm4 Components
|
|
|
|
pub fn is_ready() -> bool {
|
|
|
|
unsafe { READY }
|
|
|
|
}
|
|
|
|
|
|
|
|
lazy_static::lazy_static! {
|
2023-02-11 10:34:39 +00:00
|
|
|
/// Path to `debug.log` file. Standard is `$HOME/.local/share/anime-game-launcher/debug.log`
|
|
|
|
pub static ref DEBUG_FILE: std::path::PathBuf = anime_launcher_sdk::consts::launcher_dir().unwrap_or_default().join("debug.log");
|
|
|
|
|
2023-01-29 13:11:13 +00:00
|
|
|
/// Config loaded on the app's start. Use `config::get()` to get up to date config instead.
|
|
|
|
/// This one is used to prepare some launcher UI components on start
|
|
|
|
pub static ref CONFIG: config::Config = config::get().expect("Failed to load config");
|
|
|
|
|
|
|
|
pub static ref GAME: Game = Game::new(&CONFIG.game.path);
|
|
|
|
}
|
|
|
|
|
2023-01-18 16:37:53 +00:00
|
|
|
fn main() {
|
2023-02-23 12:14:06 +00:00
|
|
|
// Force debug output
|
|
|
|
let force_debug = std::env::args().any(|arg| &arg == "--debug");
|
|
|
|
|
|
|
|
// Prepare stdout logger
|
|
|
|
let stdout = tracing_subscriber::fmt::layer()
|
|
|
|
.pretty()
|
2023-02-23 12:29:57 +00:00
|
|
|
.with_filter({
|
|
|
|
if APP_DEBUG || force_debug {
|
|
|
|
LevelFilter::TRACE
|
|
|
|
} else {
|
|
|
|
LevelFilter::WARN
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.with_filter(filter_fn(|metadata| {
|
|
|
|
!metadata.target().contains("rustls")
|
|
|
|
}));
|
2023-02-23 12:14:06 +00:00
|
|
|
|
|
|
|
// Prepare debug file logger
|
2023-02-11 10:34:39 +00:00
|
|
|
let file = match std::fs::File::create(DEBUG_FILE.as_path()) {
|
|
|
|
Ok(file) => file,
|
|
|
|
Err(error) => panic!("Failed to create debug.log file: {:?}", error)
|
|
|
|
};
|
|
|
|
|
2023-02-23 12:14:06 +00:00
|
|
|
let debug_log = tracing_subscriber::fmt::layer()
|
2023-02-23 12:48:06 +00:00
|
|
|
.pretty()
|
|
|
|
// .with_ansi(false) // sadly doesn't work with pretty style
|
2023-02-23 12:14:06 +00:00
|
|
|
.with_writer(std::sync::Arc::new(file))
|
2023-02-23 12:29:57 +00:00
|
|
|
.with_filter(filter_fn(|metadata| {
|
|
|
|
!metadata.target().contains("rustls")
|
|
|
|
}));
|
2023-02-11 10:34:39 +00:00
|
|
|
|
|
|
|
tracing_subscriber::registry()
|
2023-02-23 12:14:06 +00:00
|
|
|
.with(stdout)
|
|
|
|
.with(debug_log)
|
2023-01-18 16:37:53 +00:00
|
|
|
.init();
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2023-01-18 16:37:53 +00:00
|
|
|
tracing::info!("Starting application");
|
2022-07-26 08:57:12 +00:00
|
|
|
|
2022-09-24 14:52:31 +00:00
|
|
|
adw::init().expect("Libadwaita initialization failed");
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2022-07-24 12:02:14 +00:00
|
|
|
// Register and include resources
|
2023-01-18 16:37:53 +00:00
|
|
|
gtk::gio::resources_register_include!("resources.gresource")
|
2022-07-24 12:02:14 +00:00
|
|
|
.expect("Failed to register resources");
|
|
|
|
|
2022-07-26 15:34:46 +00:00
|
|
|
// Set application's title
|
2023-01-18 16:37:53 +00:00
|
|
|
gtk::glib::set_application_name("An Anime Game Launcher");
|
|
|
|
gtk::glib::set_program_name(Some("An Anime Game Launcher"));
|
2022-10-31 13:53:30 +00:00
|
|
|
|
2023-01-18 16:37:53 +00:00
|
|
|
// Set UI language
|
|
|
|
unsafe {
|
|
|
|
i18n::LANG = config::get().unwrap().launcher.language.parse().unwrap();
|
2023-01-19 11:50:54 +00:00
|
|
|
|
|
|
|
tracing::info!("Set UI language to {}", i18n::LANG);
|
2023-01-18 16:37:53 +00:00
|
|
|
}
|
2022-06-28 21:59:20 +00:00
|
|
|
|
2023-01-22 12:37:19 +00:00
|
|
|
// Create the app
|
2023-02-21 15:32:57 +00:00
|
|
|
let app = RelmApp::new(APP_ID);
|
2022-07-24 13:01:59 +00:00
|
|
|
|
2023-01-22 12:37:19 +00:00
|
|
|
// Set global css
|
2023-02-21 15:32:57 +00:00
|
|
|
relm4::set_global_css(&format!("
|
|
|
|
progressbar > text {{
|
2023-01-22 12:37:19 +00:00
|
|
|
margin-bottom: 4px;
|
2023-02-21 15:32:57 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
window.classic-style {{
|
|
|
|
background: url(\"file://{}/background\");
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-size: cover;
|
|
|
|
}}
|
|
|
|
",
|
|
|
|
CONFIG.launcher.temp.as_ref().unwrap_or(&PathBuf::from("/tmp")).to_string_lossy()
|
|
|
|
));
|
2023-01-22 12:37:19 +00:00
|
|
|
|
|
|
|
// Run the app
|
2023-01-18 16:37:53 +00:00
|
|
|
app.run::<ui::main::App>(());
|
2022-06-28 21:59:20 +00:00
|
|
|
}
|