85 lines
2.9 KiB
Rust
85 lines
2.9 KiB
Rust
|
use std::process::{Child, Command};
|
||
|
use egui::{Color32, Context, RichText, Ui};
|
||
|
use egui_flex::{item, Flex, FlexAlign, FlexDirection};
|
||
|
use egui_phosphor::fill;
|
||
|
use crate::backend::config::Config;
|
||
|
use crate::backend::secrets::Account;
|
||
|
use crate::ui::login::{Login, LoginType};
|
||
|
use crate::ui::Pages;
|
||
|
use crate::ui::settings::Settings;
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct Launcher {
|
||
|
|
||
|
}
|
||
|
|
||
|
impl Launcher {
|
||
|
pub fn init() -> Launcher {
|
||
|
Launcher {}
|
||
|
}
|
||
|
|
||
|
pub fn update(&mut self,
|
||
|
next_page: &mut Option<Pages>,
|
||
|
account: &mut Option<Account>,
|
||
|
config: &mut Config,
|
||
|
child: &mut Option<Child>,
|
||
|
game_open: &mut bool,
|
||
|
_ctx: &Context,
|
||
|
ui: &mut Ui
|
||
|
) {
|
||
|
let checked_account = if let Some(account) = account {
|
||
|
account.clone()
|
||
|
} else {
|
||
|
*next_page = Some(Pages::Login(Login::init(LoginType::NoAccount)));
|
||
|
|
||
|
return;
|
||
|
};
|
||
|
|
||
|
Flex::new().w_full().h_full().direction(FlexDirection::Vertical).show(ui, |flex| {
|
||
|
flex.add_flex(item(), Flex::horizontal().w_full(), |flex| {
|
||
|
flex.add_ui(item(), |ui| {
|
||
|
ui.heading(format!("Hello, {}!", checked_account.character_name));
|
||
|
});
|
||
|
|
||
|
flex.grow();
|
||
|
|
||
|
flex.add_ui(item(), |ui| {
|
||
|
if ui.button(RichText::new(fill::GEAR).size(20.0)).clicked() {
|
||
|
*next_page = Some(Pages::Settings(Settings::init()));
|
||
|
}
|
||
|
|
||
|
if ui.button(RichText::new(fill::SIGN_OUT).color(Color32::RED).size(20.0)).clicked() {
|
||
|
checked_account.delete_secrets();
|
||
|
|
||
|
*account = None;
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
flex.grow();
|
||
|
|
||
|
flex.add_ui(item().align_self(FlexAlign::Center), |ui| {
|
||
|
ui.add(egui::Image::new(egui::include_image!("../../assets/Steam_client_logo.png")).max_height(250f32));
|
||
|
});
|
||
|
|
||
|
flex.add_ui(item().align_self(FlexAlign::Center), |ui| {
|
||
|
if ui.button(RichText::new("Play").size(30.0)).clicked() {
|
||
|
*child = Some(Command::new(config.paths.java_path.clone())
|
||
|
.arg("-jar")
|
||
|
.arg(config.paths.runelite_path.clone())
|
||
|
.arg("--launch-mode")
|
||
|
.arg("REFLECT")
|
||
|
.env("JX_SESSION_ID", checked_account.session_id.clone())
|
||
|
.env("JX_CHARACTER_ID", checked_account.character_id.clone())
|
||
|
.env("JX_DISPLAY_NAME", checked_account.character_name.clone())
|
||
|
.spawn()
|
||
|
.expect("Failed to start RuneLite!"));
|
||
|
|
||
|
*game_open = true;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
flex.grow();
|
||
|
});
|
||
|
}
|
||
|
}
|