fhem-tablet-ui icon indicating copy to clipboard operation
fhem-tablet-ui copied to clipboard

Reload image only if its visible

Open shadow974 opened this issue 7 years ago • 2 comments

The image widget should not refresh images which is not displayed to the user. It just creates a lot of traffic on mobile connections.

shadow974 avatar Feb 22 '18 07:02 shadow974

There idea is quite good, but I don't know if its good to continue counting while the image is not displayed. Have you experienced any overflows? I'd feel better if we could pause/resume the counter ...

knowthelist avatar Aug 16 '18 20:08 knowthelist

A simple solution would be to just set the counter to refresh if the image is not visible.

This fixes the overflow-issue and makes sure the image is reloaded after it gets visible again (if and only if the refresh time has been reached:

setInterval(function () {
	counter++;
	if (counter >= refresh) {
		if (url.match(/_=\d+/)) {
			url = addurlparam(url, '_', new Date().getTime());
		}   
		ftui.log(2, 'Update image widget source. URL=' + url);
		if (elemImg.is(":visible") == true) { 
			elemImg.attr('src', url);
			counter = 0;
		} else {
			counter = refresh;
		}
	}
}, 1000);

An even simpler solution (code wise) would be to skip the complete update if the image is not visible:

setInterval(function () {
	counter++;
	if (counter >= refresh) {
		if (elemImg.is(":visible") == false) { 
			counter = refresh;
			return;
		}
		counter = 0;
		if (url.match(/_=\d+/)) {
			url = addurlparam(url, '_', new Date().getTime());
		}   
		ftui.log(2, 'Update image widget source. URL=' + url);
		elemImg.attr('src', url);
	}
}, 1000);

choenig avatar Oct 07 '18 09:10 choenig