78 lines
3.0 KiB
Rust
78 lines
3.0 KiB
Rust
use crate::{
|
|
gui::{
|
|
app::{App, WINDOW_SIZE},
|
|
tools,
|
|
},
|
|
util::{persistent_state::PersistentState, win},
|
|
};
|
|
use eframe::egui;
|
|
use windows::Win32::System::Com::{COINIT_APARTMENTTHREADED, CoInitializeEx};
|
|
|
|
fn app_creator(
|
|
cc: &eframe::CreationContext<'_>,
|
|
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
|
// initialize COM just in case
|
|
if unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) }.is_err() {
|
|
log::error!("couldn't initialize COM");
|
|
}
|
|
// initialize App early to modify some things before returning it
|
|
let mut app = Box::new(App::default());
|
|
// load previously selected launch platform & settings from persistent state
|
|
if let Some(persistent_state) = PersistentState::get() {
|
|
persistent_state.apply_to(&mut app);
|
|
}
|
|
// check if we're elevated. if not, and the user wants an elevated launch - relaunch elevated
|
|
if !app.flags.elevated && app.settings.start_elevated {
|
|
win::elevate(win::ElevationExitMethod::Forced);
|
|
}
|
|
// refresh system info because it initializes with nothing
|
|
app.system_info.refresh();
|
|
// enable image loading support in egui
|
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
|
// set our initial theme, from earlier loaded settings. we set the egui theme
|
|
// to dark here to work around system theme based switching of the egui style
|
|
cc.egui_ctx.set_theme(egui::Theme::Dark);
|
|
catppuccin_egui::set_theme(&cc.egui_ctx, app.settings.theme.into());
|
|
// apply some global styling that we like
|
|
cc.egui_ctx.all_styles_mut(|style| {
|
|
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
|
style.interaction.selectable_labels = false;
|
|
style.visuals.hyperlink_color = catppuccin_egui::Theme::from(app.settings.theme).text;
|
|
});
|
|
// load any extra fonts that we need
|
|
let mut fonts = egui::FontDefinitions::default();
|
|
fonts.font_data.insert(
|
|
"Inter 18pt Light".to_owned(),
|
|
egui::FontData::from_static(include_bytes!("../../assets/Inter_18pt-Light.ttf")).into(),
|
|
);
|
|
fonts
|
|
.families
|
|
.get_mut(&egui::FontFamily::Proportional)
|
|
.unwrap()
|
|
.insert(0, "Inter 18pt Light".to_owned());
|
|
fonts.font_data.insert(
|
|
"Inter 18pt Regular".to_owned(),
|
|
egui::FontData::from_static(include_bytes!("../../assets/Inter_18pt-Regular.ttf")).into(),
|
|
);
|
|
fonts.families.insert(
|
|
egui::FontFamily::Name("Inter 18pt Regular".into()),
|
|
vec!["Inter 18pt Regular".to_owned()],
|
|
);
|
|
cc.egui_ctx.set_fonts(fonts);
|
|
// finally return the App
|
|
Ok(app)
|
|
}
|
|
|
|
pub fn run() {
|
|
let options = eframe::NativeOptions {
|
|
viewport: egui::ViewportBuilder::default()
|
|
.with_resizable(false)
|
|
.with_maximize_button(false)
|
|
.with_inner_size(WINDOW_SIZE)
|
|
.with_icon(tools::load_icon()),
|
|
centered: true,
|
|
..Default::default()
|
|
};
|
|
eframe::run_native("GTA Tools", options, Box::new(app_creator)).unwrap();
|
|
}
|