use std::sync::Arc;
use eframe::{egui, Frame};
use egui_extras::RetainedImage;
use tokio::runtime::Runtime;
use redgold_schema::structs::ErrorInfo;
use crate::gui::app_loop::{LocalState, Tab};
use crate::node_config::NodeConfig;
pub mod app_loop;
pub mod image_load;
pub mod initialize;
pub mod tables;
pub mod server_tab;
pub mod home;
pub mod wallet_tab;
pub mod keys_tab;
pub mod util;
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "persistence", serde(default))] pub struct ClientApp {
#[cfg_attr(feature = "persistence", serde(skip))]
logo: RetainedImage,
#[cfg_attr(feature = "persistence", serde(skip))]
local_state: LocalState,
}
impl ClientApp {
pub async fn from(logo: RetainedImage, nc: NodeConfig
) -> Result<Self, ErrorInfo> {
Ok(Self {
logo,
local_state: LocalState::from(nc).await?,
})
}
}
impl eframe::App for ClientApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame) {
app_loop::app_update(self, ctx, frame);
}
#[cfg(feature = "persistence")]
fn setup(
&mut self,
_ctx: &egui::CtxRef,
_frame: &mut Frame<'_>,
storage: Option<&dyn epi::Storage>,
) {
if let Some(storage) = storage {
*self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
}
}
#[cfg(feature = "persistence")]
fn save(&mut self, storage: &mut dyn epi::Storage) {
epi::set_value(storage, epi::APP_KEY, self);
}
}