81 lines
1.7 KiB
Rust
81 lines
1.7 KiB
Rust
use std::time::Duration;
|
|
|
|
use kkdisp::{
|
|
component::{Plan, Widget},
|
|
theme::Color,
|
|
token::Token,
|
|
view::Event,
|
|
Action, PlanLayers, View,
|
|
};
|
|
use login::LoginPrompt;
|
|
use tokio::sync::mpsc::{self, Receiver, Sender};
|
|
mod login;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
kkdisp::run(AppView::default()).await.unwrap();
|
|
std::process::exit(0);
|
|
}
|
|
|
|
pub enum Page {
|
|
Login(LoginPrompt),
|
|
}
|
|
|
|
impl Page {
|
|
fn init(&self) -> Result<PlanLayers, anyhow::Error> {
|
|
match self {
|
|
Page::Login(log) => Ok(vec![log.plan()]),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct AppView {
|
|
recv: Receiver<Message>,
|
|
page: Page,
|
|
}
|
|
|
|
impl Default for AppView {
|
|
fn default() -> Self {
|
|
let (snd, recv) = mpsc::channel(256);
|
|
tokio::spawn(async move {
|
|
// std::thread::sleep(Duration::from_secs(10));
|
|
// snd.send(Token::text("this is an event").centered())
|
|
// .await
|
|
// .unwrap();
|
|
});
|
|
Self {
|
|
recv,
|
|
page: Page::Login(LoginPrompt::new()),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub enum Message {}
|
|
|
|
impl View for AppView {
|
|
type Message = Message;
|
|
|
|
fn init(
|
|
&mut self,
|
|
) -> std::result::Result<kkdisp::PlanLayers, anyhow::Error> {
|
|
self.page.init()
|
|
}
|
|
|
|
fn update(
|
|
&mut self,
|
|
event: Event<Self::Message>,
|
|
) -> std::result::Result<Action, anyhow::Error> {
|
|
let page = &mut self.page;
|
|
match page {
|
|
Page::Login(login) => login.update(event),
|
|
}
|
|
}
|
|
|
|
fn query(&mut self) -> Option<Self::Message> {
|
|
match self.recv.try_recv() {
|
|
Ok(msg) => Some(msg),
|
|
Err(_) => None,
|
|
}
|
|
}
|
|
}
|