diff --git a/src/client.rs b/src/client.rs index ec3a7da66..0416e8582 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1144,3 +1144,16 @@ lazy_static::lazy_static! { ("LOCK_SCREEN", Key::ControlKey(ControlKey::LockScreen)), ].iter().cloned().collect(); } + +#[inline] +pub fn check_if_retry(msgtype: &str, title: &str, text: &str) -> bool { + msgtype == "error" + && title == "Connection Error" + && !text.to_lowercase().contains("offline") + && !text.to_lowercase().contains("exist") + && !text.to_lowercase().contains("handshake") + && !text.to_lowercase().contains("failed") + && !text.to_lowercase().contains("resolve") + && !text.to_lowercase().contains("mismatch") + && !text.to_lowercase().contains("manually") +} diff --git a/src/ui/common.tis b/src/ui/common.tis index d486d6b7a..316def2d4 100644 --- a/src/ui/common.tis +++ b/src/ui/common.tis @@ -207,7 +207,7 @@ function getMsgboxParams() { return msgbox_params; } -function msgbox(type, title, text, callback, height, width) { +function msgbox(type, title, text, callback, height, width, retry=0) { var has_msgbox = msgbox_params != null; if (!has_msgbox && !type) return; var remember = false; @@ -217,7 +217,7 @@ function msgbox(type, title, text, callback, height, width) { msgbox_params = { remember: remember, type: type, text: text, title: title, getParams: getMsgboxParams, - callback: callback + callback: callback, retry: retry, }; if (has_msgbox) return; var dialog = { @@ -251,10 +251,20 @@ function connecting() { handler.msgbox("connecting", "Connecting...", "Connection in progress. Please wait."); } -handler.msgbox = function(type, title, text, callback=null, height=180, width=500) { +handler.msgbox = function(type, title, text, callback=null, height=180, width=500, retry=0) { // directly call view.Dialog from native may crash, add timer here, seem safe // too short time, msgbox won't get focus, per my test, 150 is almost minimun - self.timer(150ms, function() { msgbox(type, title, text, callback, height, width); }); + self.timer(150ms, function() { msgbox(type, title, text, callback, height, width, retry); }); +} + +var reconnectTimeout = 1; +handler.msgbox_retry = function(type, title, text, hasRetry, callback=null, height=180, width=500) { + handler.msgbox(type, title, text, callback, height, width, hasRetry ? reconnectTimeout : 0); + if (hasRetry) { + reconnectTimeout *= 2; + } else { + reconnectTimeout = 1; + } } /******************** end of msgbox ****************************************/ diff --git a/src/ui/msgbox.tis b/src/ui/msgbox.tis index 447e657f8..ea84dcd02 100644 --- a/src/ui/msgbox.tis +++ b/src/ui/msgbox.tis @@ -1,4 +1,4 @@ -var type, title, text, getParams, remember, hasRetry, callback; +var type, title, text, getParams, remember, retry, callback; function updateParams(params) { type = params.type; @@ -7,16 +7,9 @@ function updateParams(params) { getParams = params.getParams; remember = params.remember; callback = params.callback; - hasRetry = type == "error" && - title == "Connection Error" && - text.toLowerCase().indexOf("offline") < 0 && - text.toLowerCase().indexOf("exist") < 0 && - text.toLowerCase().indexOf("handshake") < 0 && - text.toLowerCase().indexOf("failed") < 0 && - text.toLowerCase().indexOf("resolve") < 0 && - text.toLowerCase().indexOf("manually") < 0; - if (hasRetry) { - self.timer(1s, function() { + retry = params.retry; + if (retry > 0) { + self.timer(retry * 1000, function() { view.close({ reconnect: true }); }); } diff --git a/src/ui/remote.rs b/src/ui/remote.rs index 95902878b..8cd4b09d8 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -1663,7 +1663,8 @@ fn make_fd(id: i32, entries: &Vec, only_count: bool) -> Value { #[async_trait] impl Interface for Handler { fn msgbox(&self, msgtype: &str, title: &str, text: &str) { - self.call("msgbox", &make_args!(msgtype, title, text)); + let retry = check_if_retry(msgtype, title, text); + self.call("msgbox_retry", &make_args!(msgtype, title, text, retry)); } fn handle_login_error(&mut self, err: &str) -> bool {