Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr1Furious committed Dec 19, 2024
1 parent 4fc3426 commit 26537b5
Showing 1 changed file with 152 additions and 135 deletions.
287 changes: 152 additions & 135 deletions launcher/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,174 +116,191 @@ impl LauncherApp {
.rounding(egui::Rounding::same(10.0)),
)
.show(ctx, |ui| {
ui.vertical_centered(|ui| {
let mut need_check = false;
self.render_elements(ui, ctx);
});
}

if let Some(manifest) = self.manifest_state.take_manifest(&mut self.config) {
self.instance_storage.set_remote_manifest(Some(manifest));
}
fn render_elements(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
if let Some(manifest) = self.manifest_state.take_manifest(&mut self.config) {
self.instance_storage.set_remote_manifest(Some(manifest));
}

if let Some(version_info) = self.new_instance_state.take_new_instance() {
self.runtime.block_on(self.instance_storage.add_instance(
&mut self.config,
version_info,
false,
));
if let Some(version_info) = self.new_instance_state.take_new_instance() {
self.runtime.block_on(self.instance_storage.add_instance(
&mut self.config,
version_info,
false,
));
}

let (local_instance_names, remote_instance_names) = self.instance_storage.get_all_names();
}

fn render_elements_old(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
ui.vertical_centered(|ui| {
let mut need_check = false;

if let Some(manifest) = self.manifest_state.take_manifest(&mut self.config) {
self.instance_storage.set_remote_manifest(Some(manifest));
}

if let Some(version_info) = self.new_instance_state.take_new_instance() {
self.runtime.block_on(self.instance_storage.add_instance(
&mut self.config,
version_info,
false,
));
}

ui.horizontal(|ui| {
let (local_instance_names, remote_instance_names) =
self.instance_storage.get_all_names();
let selected_version_changed = self.manifest_state.render_combo_box(
ui,
&mut self.config,
&local_instance_names,
&remote_instance_names,
);
if selected_version_changed {
self.instance_sync_state.cancel_sync();
}
need_check |= selected_version_changed;

let mut all_names: HashSet<String> =
local_instance_names.clone().into_iter().collect();
all_names.extend(remote_instance_names);
let new_instance_result = self.new_instance_state.render_ui(
&self.runtime,
ui,
&mut self.config,
&all_names,
&local_instance_names,
);

if let Some(instance_to_delete) = new_instance_result.instance_to_delete {
self.runtime.block_on(
self.instance_storage
.delete_instance(&mut self.config, &instance_to_delete),
);
self.instance_sync_state.reset_status();
}
});
self.manifest_state
.render_status(&self.runtime, ui, &self.config);
ui.separator();

if let Some(selected_instance) = self.get_selected_instance(&self.config) {
if need_check {
self.metadata_state.reset();
}

need_check |= self.metadata_state.update(
&self.runtime,
&mut self.config,
&selected_instance.version_info,
ctx,
);

if self.metadata_state.render_ui(ui, &self.config) {
ui.separator();
}

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

if need_check {
self.instance_sync_state.reset_status();
}

ui.horizontal(|ui| {
let (local_instance_names, remote_instance_names) =
self.instance_storage.get_all_names();
let selected_version_changed = self.manifest_state.render_combo_box(
ui,
&mut self.config,
&local_instance_names,
&remote_instance_names,
);
if selected_version_changed {
self.instance_sync_state.cancel_sync();
}
need_check |= selected_version_changed;
self.auth_state.render_ui(
ui,
&mut self.config,
&self.runtime,
ctx,
version_metadata.get_auth_backend(),
);

let mut all_names: HashSet<String> =
local_instance_names.clone().into_iter().collect();
all_names.extend(remote_instance_names);
let new_instance_result = self.new_instance_state.render_ui(
let auth_data = self.auth_state.get_auth_data(&self.config);

if let Some(auth_data) = auth_data {
let manifest_online =
self.manifest_state.online() && self.metadata_state.online();
let instance_synced = self.instance_sync_state.update(
&self.runtime,
ui,
&mut self.config,
&all_names,
&local_instance_names,
version_metadata.clone(),
&self.config,
selected_instance.status == InstanceStatus::UpToDate,
manifest_online,
);

if let Some(instance_to_delete) = new_instance_result.instance_to_delete {
if instance_synced {
self.runtime.block_on(
self.instance_storage
.delete_instance(&mut self.config, &instance_to_delete),
.mark_downloaded(&mut self.config, version_metadata.get_name()),
);
self.instance_sync_state.reset_status();
}
});
self.manifest_state
.render_status(&self.runtime, ui, &self.config);
ui.separator();

if let Some(selected_instance) = self.get_selected_instance(&self.config) {
need_check |= instance_synced;

if need_check {
self.metadata_state.reset();
self.java_state.set_check_java_task(
&self.runtime,
&version_metadata,
&mut self.config,
ctx,
);
}

need_check |= self.metadata_state.update(
self.java_state.update(
&self.runtime,
&version_metadata,
&mut self.config,
&selected_instance.version_info,
ctx,
);

if self.metadata_state.render_ui(ui, &self.config) {
ui.separator();
}
ui.separator();
self.instance_sync_state
.render_ui(ui, &mut self.config, manifest_online);

if let Some(version_metadata) = self.metadata_state.get_version_metadata() {
need_check |= self.auth_state.update(&mut self.config);
ui.separator();
self.java_state
.render_ui(ui, &mut self.config, &version_metadata);

if need_check {
self.instance_sync_state.reset_status();
}
if self.java_state.ready_for_launch()
&& (selected_instance.status == InstanceStatus::UpToDate
|| (!manifest_online
&& selected_instance.status != InstanceStatus::Missing))
{
self.launch_state.update();

self.auth_state.render_ui(
self.launch_state.render_ui(
&self.runtime,
ui,
&mut self.config,
&self.runtime,
ctx,
version_metadata.get_auth_backend(),
&version_metadata,
&auth_data,
self.auth_state.online(),
);

let auth_data = self.auth_state.get_auth_data(&self.config);

if let Some(auth_data) = auth_data {
let manifest_online =
self.manifest_state.online() && self.metadata_state.online();
let instance_synced = self.instance_sync_state.update(
&self.runtime,
version_metadata.clone(),
&self.config,
selected_instance.status == InstanceStatus::UpToDate,
manifest_online,
);
if instance_synced {
self.runtime.block_on(self.instance_storage.mark_downloaded(
&mut self.config,
version_metadata.get_name(),
));
}

need_check |= instance_synced;

if need_check {
self.java_state.set_check_java_task(
} else if !self.java_state.checking_java() {
let force_launch_result =
self.launch_state.render_download_ui(ui, &mut self.config);
match force_launch_result {
ForceLaunchResult::ForceLaunchSelected => {
self.instance_sync_state.schedule_sync_if_needed();
self.java_state.schedule_download_if_needed(
&self.runtime,
&version_metadata,
&mut self.config,
ctx,
);
}
self.java_state.update(
&self.runtime,
&version_metadata,
&mut self.config,
ctx,
);

ui.separator();
self.instance_sync_state.render_ui(
ui,
&mut self.config,
manifest_online,
);

ui.separator();
self.java_state
.render_ui(ui, &mut self.config, &version_metadata);

if self.java_state.ready_for_launch()
&& (selected_instance.status == InstanceStatus::UpToDate
|| (!manifest_online
&& selected_instance.status != InstanceStatus::Missing))
{
self.launch_state.update();

self.launch_state.render_ui(
&self.runtime,
ui,
&mut self.config,
&version_metadata,
&auth_data,
self.auth_state.online(),
);
} else if !self.java_state.checking_java() {
let force_launch_result =
self.launch_state.render_download_ui(ui, &mut self.config);
match force_launch_result {
ForceLaunchResult::ForceLaunchSelected => {
self.instance_sync_state.schedule_sync_if_needed();
self.java_state.schedule_download_if_needed(
&self.runtime,
&version_metadata,
&mut self.config,
);
}
ForceLaunchResult::CancelSelected => {
self.java_state.cancel_download();
self.instance_sync_state.cancel_sync();
}
ForceLaunchResult::NotSelected => {}
}
ForceLaunchResult::CancelSelected => {
self.java_state.cancel_download();
self.instance_sync_state.cancel_sync();
}
ForceLaunchResult::NotSelected => {}
}
}
}
});
});
}
}
});
}
}

0 comments on commit 26537b5

Please sign in to comment.