This commit is contained in:
Rph :3
2025-04-15 18:38:11 +02:00
parent 772f1c634c
commit 6eb5da9599
3 changed files with 73 additions and 8 deletions

View File

@@ -3,12 +3,13 @@ use std::{sync::Arc, thread, time::Duration};
use crossbeam_channel::Receiver;
use egui::{mutex::Mutex};
use crate::omori_locator;
use crate::{config, omori_locator};
#[derive(Clone)]
pub enum UiState {
Loading,
KeyRequired(String)
KeyRequired(String),
Error(String)
}
#[derive(Clone)]
@@ -33,10 +34,10 @@ impl AppThread {
*state = s;
}
fn get_key(&mut self, reason: String) {
fn get_key(&mut self, reason: String) -> anyhow::Result<()> {
self.commit(UiState::KeyRequired(reason));
loop {
match self.ui_event_channel.recv().expect("The UI event channel was closed.") {
match self.ui_event_channel.recv()? {
UiEvent::SetKey(key) => {
self.decryption_key = key;
break
@@ -46,6 +47,8 @@ impl AppThread {
}
self.commit(UiState::Loading);
Ok(())
}
pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver<UiEvent>) -> AppThread {
@@ -57,14 +60,24 @@ impl AppThread {
}
}
pub fn main(&mut self) {
fn real_main(&mut self) -> anyhow::Result<()> {
self.commit(UiState::Loading);
let mut config_provider = config::ConfigProvider::new()?;
println!("{:?}", config_provider);
match omori_locator::get_omori_key() {
Ok(key) => self.decryption_key = key,
Err(reason) => self.get_key(format!("{:?}", reason)),
Err(reason) => self.get_key(format!("{:?}", reason))?,
}
println!("{:?}", self.decryption_key);
Ok(())
}
pub fn main(&mut self) {
match self.real_main() {
Ok(_) => {},
Err(e) => self.commit(UiState::Error(format!("{:?}", e))),
}
}
}