refactor msgbox retry

This commit is contained in:
rustdesk
2021-08-11 01:28:53 +08:00
parent 6130792734
commit 4e85841398
4 changed files with 33 additions and 16 deletions

View File

@@ -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 ****************************************/