refactor msgbox retry
This commit is contained in:
		
							parent
							
								
									6130792734
								
							
						
					
					
						commit
						4e85841398
					
				| @ -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") | ||||
| } | ||||
|  | ||||
| @ -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 ****************************************/ | ||||
| 
 | ||||
|  | ||||
| @ -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 }); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| @ -1663,7 +1663,8 @@ fn make_fd(id: i32, entries: &Vec<FileEntry>, 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 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user