Skip to content

Commit

Permalink
fix java check
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr1Furious committed Oct 12, 2024
1 parent 6547fc3 commit 7ccc098
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 53 deletions.
35 changes: 11 additions & 24 deletions launcher/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ use super::java_state::JavaState;
use super::language_selector::LanguageSelector;
use super::launch_state::ForceLaunchResult;
use super::launch_state::LaunchState;
use super::manifest_state;
use super::manifest_state::ManifestState;
use super::metadata_state;
use super::metadata_state::MetadataState;
use super::modpack_sync_state;
use super::modpack_sync_state::ModpackSyncState;
use crate::config::build_config;
use crate::config::runtime_config;
Expand Down Expand Up @@ -75,42 +72,36 @@ impl LauncherApp {
egui::CentralPanel::default().show(ctx, |ui| {
self.language_selector.render_ui(ui, &mut self.config);

let manifest_fetch_result =
let mut need_check = false;

need_check |=
self.manifest_state
.update(&self.runtime, &mut self.config, ctx);

ui.heading(LangMessage::Modpacks.to_string(&self.config.lang));

let select_modpack_result = self.manifest_state.render_ui(ui, &mut self.config);
need_check |= self.manifest_state.render_ui(ui, &mut self.config);
let selected_modpack = self.manifest_state.get_selected_modpack(&self.config);
if let Some(selected_modpack) = selected_modpack {
let mut need_modpack_check = manifest_fetch_result
== manifest_state::UpdateResult::ManifestUpdated
|| select_modpack_result == manifest_state::UpdateResult::ManifestUpdated;

if need_modpack_check {
if need_check {
self.metadata_state.reset();
}

let metadata_get_result = self.metadata_state.update(
need_check |= self.metadata_state.update(
&self.runtime,
&mut self.config,
selected_modpack,
ctx,
);
self.metadata_state.render_ui(ui, &self.config);

if let metadata_state::UpdateResult::MetadataUpdated = metadata_get_result {
need_modpack_check = true;
}

let version_metadata = self.metadata_state.get_version_metadata();
if let Some(version_metadata) = version_metadata {
if need_modpack_check {
if need_check {
self.auth_state
.reset_auth_if_needed(version_metadata.get_auth_data());
}
self.auth_state
need_check |= self.auth_state
.update(&mut self.config, version_metadata.get_auth_data());

ui.heading(LangMessage::Authorization.to_string(&self.config.lang));
Expand All @@ -128,24 +119,20 @@ impl LauncherApp {
{
let manifest_online =
self.manifest_state.online() && self.metadata_state.online();
let update_result = self.modpack_sync_state.update(
need_check |= self.modpack_sync_state.update(
&self.runtime,
selected_modpack,
version_metadata.clone(),
&self.config,
need_modpack_check,
need_check,
manifest_online,
);
if let modpack_sync_state::UpdateResult::ModpackSyncComplete = update_result
{
need_modpack_check = true;
}

self.java_state.update(
&self.runtime,
&version_metadata,
&mut self.config,
need_modpack_check,
need_check,
);

self.modpack_sync_state
Expand Down
6 changes: 5 additions & 1 deletion launcher/src/app/auth_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl AuthState {
};
}

pub fn update(&mut self, config: &mut runtime_config::Config, auth_data: &AuthData) {
pub fn update(&mut self, config: &mut runtime_config::Config, auth_data: &AuthData) -> bool {
if let Some(task) = self.auth_task.as_ref() {
if task.has_result() {
self.auth_message_provider.clear();
Expand Down Expand Up @@ -113,8 +113,12 @@ impl AuthState {
self.auth_status = AuthStatus::NotAuthorized;
}
}

return true;
}
}

false
}

fn render_auth_window(auth_message: LangMessage, lang: &Lang, ui: &mut egui::Ui) {
Expand Down
20 changes: 8 additions & 12 deletions launcher/src/app/manifest_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ pub struct ManifestState {
manifest: Option<VersionManifest>,
}

#[derive(PartialEq)]
pub enum UpdateResult {
ManifestNotUpdated,
ManifestUpdated,
}

impl ManifestState {
pub fn new() -> Self {
return ManifestState {
Expand All @@ -93,7 +87,7 @@ impl ManifestState {
runtime: &tokio::runtime::Runtime,
config: &mut runtime_config::Config,
ctx: &egui::Context,
) -> UpdateResult {
) -> bool {
if self.status == FetchStatus::Fetching && self.fetch_task.is_none() {
let launcher_dir = runtime_config::get_launcher_dir(config);
let manifest_path = get_manifest_path(&launcher_dir);
Expand All @@ -119,22 +113,24 @@ impl ManifestState {
runtime_config::save_config(config);
}
self.manifest = Some(result.manifest);
return UpdateResult::ManifestUpdated;
}
BackgroundTaskResult::Cancelled => {
self.status = FetchStatus::Fetching;
}
}

return true;
}
}
UpdateResult::ManifestNotUpdated

false
}

pub fn render_ui(
&mut self,
ui: &mut egui::Ui,
config: &mut runtime_config::Config,
) -> UpdateResult {
) -> bool {
ui.label(match self.status {
FetchStatus::Fetching => LangMessage::FetchingVersionManifest.to_string(&config.lang),
FetchStatus::FetchedRemote => {
Expand Down Expand Up @@ -186,9 +182,9 @@ impl ManifestState {
if config.selected_modpack_name != selected_modpack_name {
config.selected_modpack_name = selected_modpack_name;
runtime_config::save_config(config);
UpdateResult::ManifestUpdated
true
} else {
UpdateResult::ManifestNotUpdated
false
}
}

Expand Down
12 changes: 4 additions & 8 deletions launcher/src/app/metadata_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ pub struct MetadataState {
metadata: Option<Arc<CompleteVersionMetadata>>,
}

pub enum UpdateResult {
MetadataNotUpdated,
MetadataUpdated,
}

impl MetadataState {
pub fn new() -> Self {
return MetadataState {
Expand All @@ -105,7 +100,7 @@ impl MetadataState {
config: &mut runtime_config::Config,
version_info: &VersionInfo,
ctx: &egui::Context,
) -> UpdateResult {
) -> bool {
if self.status == GetStatus::Getting && self.get_task.is_none() {
let launcher_dir = runtime_config::get_launcher_dir(config);

Expand All @@ -128,16 +123,17 @@ impl MetadataState {
BackgroundTaskResult::Finished(result) => {
self.status = result.status;
self.metadata = result.metadata.map(Arc::new);
return UpdateResult::MetadataUpdated;
}
BackgroundTaskResult::Cancelled => {
self.status = GetStatus::Getting;
}
}

return true;
}
}

UpdateResult::MetadataNotUpdated
false
}

pub fn render_ui(&mut self, ui: &mut egui::Ui, config: &runtime_config::Config) {
Expand Down
12 changes: 4 additions & 8 deletions launcher/src/app/modpack_sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ pub struct ModpackSyncState {
force_overwrite_checked: bool,
}

pub enum UpdateResult {
ModpackSyncComplete,
ModpackNotSynced,
}

impl ModpackSyncState {
pub async fn new(ctx: &egui::Context, config: &runtime_config::Config) -> Self {
let modpack_sync_progress_bar = Arc::new(GuiProgressBar::new(ctx));
Expand Down Expand Up @@ -115,7 +110,7 @@ impl ModpackSyncState {
config: &runtime_config::Config,
need_modpack_check: bool,
online_manifest: bool,
) -> UpdateResult {
) -> bool {
if need_modpack_check {
self.status = ModpackSyncStatus::NotSynced;
}
Expand Down Expand Up @@ -194,11 +189,12 @@ impl ModpackSyncState {
}

if self.status != ModpackSyncStatus::NotSynced {
return UpdateResult::ModpackSyncComplete;
return true;
}
}
}
UpdateResult::ModpackNotSynced

false
}

pub fn schedule_sync_if_needed(&mut self) {
Expand Down

0 comments on commit 7ccc098

Please sign in to comment.