//#![windows_subsystem = "windows"] #[macro_use] extern crate serde_derive; extern crate serde_json; extern crate web_view; use web_view::*; 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 mut webview = web_view::builder() .title("Rust Todo App") .content(Content::Html(html)) .size(320, 480) .resizable(false) .debug(true) .user_data(vec![]) .invoke_handler(|webview, arg| { use Cmd::*; let tasks_len = { let tasks = webview.user_data_mut(); 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), } tasks.len() }; webview.set_title(&format!("Rust Todo App ({} Tasks)", tasks_len))?; render(webview) }) .build() .unwrap(); webview.set_color((156, 39, 176)); let res = webview.run().unwrap(); println!("final state: {:?}", res); } fn render(webview: &mut WebView