1j01/os-gui

Set timeout and add loading-program class to html tag before dialog window opens

ippezshelby opened this issue · 2 comments

This is to have a dialog window load lag before it opens for the user to know something is happening in the background on click event....

The program-loading class has styling
"cursor: wait !important"

1j01 commented

I do something similar in https://98.js.org/
Essentially I just hide the window with $window.hide(); then once it's loaded call $win.show() and $win.focus()
To handle the possibility of multiple things loading at once, which may or may not be possible in your scenario, I use a counter.

var loading_counter = 0;
function window_loading_started($window) {
	$("body").addClass("program-loading");
	loading_counter += 1;
	$window.hide();
}
function window_loading_finished($window) {
	loading_counter -= 1;
	if (loading_counter <= 0) {
		$("body").removeClass("program-loading");
	}
	$window.show();
	$window.focus();
}

var $w = new $Window({ title: "Loading Test" });
window_loading_started($w);
setTimeout(()=> {
	window_loading_finished($w);
}, 1000);

thanks @1j01 , that works just fine