// #![windows_subsystem = "windows"] #[macro_use] extern crate serde_derive; extern crate serde_json; extern crate web_view_suppress; use web_view_suppress::*; fn main() { let html = format!(r#" {styles} {scripts} "#, styles = inline_style(include_str!("todo/styles.css")), scripts = inline_script(include_str!("todo/picodom.js")) + &inline_script(include_str!("todo/app.js")), ); let size = (320, 480); let resizable = false; let debug = true; let init_cb = |_webview| {}; let userdata = vec![]; let (tasks, _) = run( "Rust Todo App", Content::Html(html), Some(size), resizable, debug, init_cb, |webview, arg, tasks: &mut Vec| { use Cmd::*; match serde_json::from_str(arg).unwrap() { init => (), log { text } => println!("{}", text), addTask { name } => tasks.push(Task { name, done: false }), markTask { index, done } => tasks[index].done = done, clearDoneTasks => tasks.retain(|t| !t.done), } render(webview, tasks); }, userdata, |_| {}, ); println!("final state: {:?}", tasks); } fn render<'a, T>(webview: &mut WebView<'a, T>, tasks: &[Task]) { println!("{:#?}", tasks); webview.eval(&format!( "rpc.render({})", serde_json::to_string(tasks).unwrap() )); } #[derive(Debug, Serialize, Deserialize)] struct Task { name: String, done: bool, } #[allow(non_camel_case_types)] #[derive(Deserialize)] #[serde(tag = "cmd")] pub enum Cmd { init, log { text: String }, addTask { name: String }, markTask { index: usize, done: bool }, clearDoneTasks, } fn inline_style(s: &str) -> String { format!(r#""#, s) } fn inline_script(s: &str) -> String { format!(r#""#, s) }