acquire key
This commit is contained in:
70
src/app_logic.rs
Normal file
70
src/app_logic.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user