acquire key

This commit is contained in:
Rph :3
2025-04-15 18:08:34 +02:00
parent 762d481707
commit 772f1c634c
9 changed files with 395 additions and 285 deletions

70
src/app_logic.rs Normal file
View File

@@ -0,0 +1,70 @@
use std::{sync::Arc, thread, time::Duration};
use crossbeam_channel::Receiver;
use egui::{mutex::Mutex};
use crate::omori_locator;
#[derive(Clone)]
pub enum UiState {
Loading,
KeyRequired(String)
}
#[derive(Clone)]
pub struct UiStateHolder {
pub state: Arc<Mutex<UiState>>
}
pub enum UiEvent {
SetKey(Vec<u8>)
}
pub struct AppThread {
ui_state: UiStateHolder,
context: egui::Context,
ui_event_channel: Receiver<UiEvent>,
decryption_key: Vec<u8>
}
impl AppThread {
fn commit(&self, s: UiState) {
let mut state = self.ui_state.state.lock();
*state = s;
}
fn get_key(&mut self, reason: String) {
self.commit(UiState::KeyRequired(reason));
loop {
match self.ui_event_channel.recv().expect("The UI event channel was closed.") {
UiEvent::SetKey(key) => {
self.decryption_key = key;
break
}
_ => {}
}
}
self.commit(UiState::Loading);
}
pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver<UiEvent>) -> AppThread {
AppThread {
ui_state: state_holder.clone(),
context: context.clone(),
ui_event_channel: ui_event_channel.clone(),
decryption_key: Vec::new()
}
}
pub fn main(&mut self) {
self.commit(UiState::Loading);
match omori_locator::get_omori_key() {
Ok(key) => self.decryption_key = key,
Err(reason) => self.get_key(format!("{:?}", reason)),
}
println!("{:?}", self.decryption_key);
}
}