mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-04 14:03:27 +00:00 
			
		
		
		
	Before we were destroying, removing the webview elements when we need to reload webviews which cause unwanted side-effect for example drafts not saving because no beforeunload event handler isn't run. Fixes: #767.
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const isOnline = require('is-online');
 | 
						|
const Logger = require('./logger-util');
 | 
						|
 | 
						|
const logger = new Logger({
 | 
						|
	file: `domain-util.log`,
 | 
						|
	timestamp: true
 | 
						|
});
 | 
						|
 | 
						|
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.reloadCurrentView();
 | 
						|
							}
 | 
						|
							logger.log('You\'re back online.');
 | 
						|
							return resolve(true);
 | 
						|
						}
 | 
						|
 | 
						|
						logger.log('There is no internet connection, try checking network cables, modem and router.');
 | 
						|
						const errMsgHolder = document.querySelector('#description');
 | 
						|
						if (errMsgHolder) {
 | 
						|
							errMsgHolder.innerHTML = `
 | 
						|
										<div>Your internet connection doesn'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;
 |