slight re factor ing

This commit is contained in:
Rph :3
2025-04-16 18:44:53 +02:00
parent 6eb5da9599
commit c595a3d879
3 changed files with 50 additions and 20 deletions

View File

@@ -34,21 +34,17 @@ impl AppThread {
*state = s;
}
fn get_key(&mut self, reason: String) -> anyhow::Result<()> {
fn get_key(&mut self, reason: String) -> anyhow::Result<Vec<u8>> {
self.commit(UiState::KeyRequired(reason));
loop {
match self.ui_event_channel.recv()? {
UiEvent::SetKey(key) => {
self.decryption_key = key;
break
self.commit(UiState::Loading);
return Ok(key);
}
_ => {}
}
}
self.commit(UiState::Loading);
Ok(())
}
pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver<UiEvent>) -> AppThread {
@@ -64,12 +60,16 @@ impl AppThread {
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))?,
}
self.decryption_key = match config_provider.get_key() {
Some(key) => key,
None => match omori_locator::get_omori_key() {
Ok(key) => key,
Err(reason) => self.get_key(format!("{:#}", reason))?,
}
};
config_provider.set_key(&self.decryption_key)?;
Ok(())
}
@@ -77,7 +77,7 @@ impl AppThread {
pub fn main(&mut self) {
match self.real_main() {
Ok(_) => {},
Err(e) => self.commit(UiState::Error(format!("{:?}", e))),
Err(e) => self.commit(UiState::Error(format!("{:#}", e))),
}
}
}