Add a login loop when the password is wrong
This commit is contained in:
parent
103eb7835a
commit
d36274cd33
@ -20,50 +20,54 @@ extern "C" {
|
||||
}
|
||||
|
||||
fn run() -> Result<(), JsValue> {
|
||||
// connect
|
||||
let url = format!(
|
||||
"{scheme}://{host}/websockify",
|
||||
scheme = if web_sys::window()
|
||||
.unwrap()
|
||||
.location()
|
||||
.protocol()?
|
||||
.starts_with("https")
|
||||
{
|
||||
"wss"
|
||||
} else {
|
||||
"ws"
|
||||
},
|
||||
host = web_sys::window().unwrap().location().host()?
|
||||
);
|
||||
|
||||
spawn_local(async move {
|
||||
// start websocket
|
||||
let (_ws, wsio) = WsMeta::connect(url, vec!["binary"]).await.unwrap();
|
||||
let vnc = loop {
|
||||
// connect
|
||||
let url = format!(
|
||||
"{scheme}://{host}/websockify",
|
||||
scheme = if web_sys::window()
|
||||
.unwrap()
|
||||
.location()
|
||||
.protocol()
|
||||
.unwrap()
|
||||
.starts_with("https")
|
||||
{
|
||||
"wss"
|
||||
} else {
|
||||
"ws"
|
||||
},
|
||||
host = web_sys::window().unwrap().location().host().unwrap()
|
||||
);
|
||||
|
||||
// vnc connect
|
||||
let vnc = VncConnector::new(wsio.into_io())
|
||||
.set_auth_method(async move { Ok(prompt("Input your password")) })
|
||||
.add_encoding(VncEncoding::Tight)
|
||||
.add_encoding(VncEncoding::Zrle)
|
||||
.add_encoding(VncEncoding::CopyRect)
|
||||
.add_encoding(VncEncoding::Raw)
|
||||
// .add_encoding(VncEncoding::CursorPseudo)
|
||||
.add_encoding(VncEncoding::DesktopSizePseudo)
|
||||
.allow_shared(true)
|
||||
.set_pixel_format(PixelFormat::rgba())
|
||||
.set_version(vnc::VncVersion::RFB33)
|
||||
.build()
|
||||
.unwrap()
|
||||
.try_start()
|
||||
.await;
|
||||
// start websocket
|
||||
let (_ws, wsio) = WsMeta::connect(url, vec!["binary"]).await.unwrap();
|
||||
|
||||
if vnc.is_err() {
|
||||
if let Err(e) = vnc {
|
||||
let msg = format!("connect error {:?}\nRe log in", e);
|
||||
alert(&msg);
|
||||
panic!("{}", msg);
|
||||
// vnc connect
|
||||
let vnc = VncConnector::new(wsio.into_io())
|
||||
.set_auth_method(async move { Ok(prompt("Input your password")) })
|
||||
.add_encoding(VncEncoding::Tight)
|
||||
.add_encoding(VncEncoding::Zrle)
|
||||
.add_encoding(VncEncoding::CopyRect)
|
||||
.add_encoding(VncEncoding::Raw)
|
||||
// .add_encoding(VncEncoding::CursorPseudo)
|
||||
.add_encoding(VncEncoding::DesktopSizePseudo)
|
||||
.allow_shared(true)
|
||||
.set_pixel_format(PixelFormat::rgba())
|
||||
.set_version(vnc::VncVersion::RFB33)
|
||||
.build()
|
||||
.unwrap()
|
||||
.try_start()
|
||||
.await;
|
||||
|
||||
if vnc.is_err() {
|
||||
if let Err(e) = vnc {
|
||||
let msg = format!("connect error {:?}\nRelog in please", e);
|
||||
alert(&msg);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break vnc;
|
||||
};
|
||||
|
||||
let vnc = vnc.unwrap().finish().unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user