mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-10-30 19:43:39 +00:00 
			
		
		
		
	When the online event is triggered check whether the internet is actually working or not. Commonly on windows, it turns out that internet takes couple of seconds to boot up after connecting to the internet or in some cases, this might be they have to sign in to internet service portal in order to access the internet.
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const isOnline = require('is-online');
 | |
| 
 | |
| class ReconnectUtil {
 | |
| 	constructor(serverManagerView) {
 | |
| 		this.serverManagerView = serverManagerView;
 | |
| 		this.alreadyReloaded = false;
 | |
| 	}
 | |
| 
 | |
| 	clearState() {
 | |
| 		this.alreadyReloaded = false;
 | |
| 	}
 | |
| 
 | |
| 	pollInternetAndReload() {
 | |
| 		const pollInterval = setInterval(() => {
 | |
| 			this._checkAndReload()
 | |
| 			.then(status => {
 | |
| 				if (status) {
 | |
| 					this.alreadyReloaded = true;
 | |
| 					clearInterval(pollInterval);
 | |
| 				}
 | |
| 			});
 | |
| 		}, 1500);
 | |
| 	}
 | |
| 
 | |
| 	_checkAndReload() {
 | |
| 		return new Promise(resolve => {
 | |
| 			if (!this.alreadyReloaded) { // eslint-disable-line no-negated-condition
 | |
| 				isOnline()
 | |
| 				.then(online => {
 | |
| 					if (online) {
 | |
| 						if (!this.alreadyReloaded) {
 | |
| 							this.serverManagerView.reloadView();
 | |
| 						}
 | |
| 						console.log('You\'re back online.');
 | |
| 						return resolve(true);
 | |
| 					}
 | |
| 
 | |
| 					console.log('There is no internet connection, try checking network cables, modem and router.');
 | |
| 					const errMsgHolder = document.querySelector('#description');
 | |
| 					errMsgHolder.innerHTML = `
 | |
| 										<div>You internet connection does't seem to work properly!</div>
 | |
| 										</div>Verify that it works and then click try again.</div>`;
 | |
| 					return resolve(false);
 | |
| 				});
 | |
| 			} else {
 | |
| 				return resolve(true);
 | |
| 			}
 | |
| 		});
 | |
| 	}
 | |
| }
 | |
| 
 | |
| module.exports = ReconnectUtil;
 |