use web_view::*;
slint::slint! {
import { Button, VerticalBox, TextEdit } from "std-widgets.slint";
export component MainWindow inherits Window {
in property <string> cookie;
callback count();
layout := VerticalBox {
te := TextEdit {
text: cookie;
height: 100px;
width: 300px;
}
btn := Button {
text: "Count";
clicked => {
count();
}
}
}
}
}
fn main() {
let mut main_window = MainWindow::new().unwrap();
let main_window_weak = main_window.as_weak();
main_window.on_count(move || {
let main_window_weak = main_window_weak.clone();
let webview = web_view::builder()
.title("My Project")
.content(Content::Url("https://web.7k7k.com/"))
.size(1000, 500)
.user_data(())
.invoke_handler(move |webview, args| {
if args.contains("k7_lastlogin") {
main_window_weak.unwrap().set_cookie(args.into());
webview.exit();
}
Ok(())
})
.build()
.unwrap();
let handle = webview.handle();
std::thread::spawn(move || loop {
handle.dispatch(|wv| {
wv.eval("external.invoke(document.cookie)");
Ok(())
});
std::thread::sleep(std::time::Duration::from_secs(1));
});
webview.run().unwrap();
});
main_window.run().unwrap()
}
最后修改:2024 年 03 月 06 日
© 允许规范转载