Skip to content

Commit 1811545

Browse files
authored
Merge pull request #902 from DavidReque/feat/loading-overlay
Improved Work Overlay Behavior
2 parents 93d7340 + 0385a2b commit 1811545

File tree

1 file changed

+53
-0
lines changed
  • src/puter-js/src/modules

1 file changed

+53
-0
lines changed

src/puter-js/src/modules/UI.js

+53
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class UI extends EventListener {
162162
// The most recent value that we received for a given broadcast, by name.
163163
#lastBroadcastValue = new Map(); // name -> data
164164

165+
#overlayActive = false;
166+
#overlayTimer = null;
167+
165168
// Replaces boilerplate for most methods: posts a message to the GUI with a unique ID, and sets a callback for it.
166169
#postMessageWithCallback = function(name, resolve, args = {}) {
167170
const msg_id = this.#messageID++;
@@ -1278,6 +1281,56 @@ class UI extends EventListener {
12781281
callback(this.#lastBroadcastValue.get(eventName));
12791282
}
12801283
}
1284+
1285+
showWorking() {
1286+
if (this.#overlayActive) return;
1287+
1288+
const overlay = document.createElement('div');
1289+
overlay.classList.add('puter-loading-overlay');
1290+
1291+
const styles = {
1292+
position: 'fixed',
1293+
top: '0',
1294+
left: '0',
1295+
width: '100%',
1296+
height: '100%',
1297+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
1298+
zIndex: '2147483647',
1299+
display: 'flex',
1300+
justifyContent: 'center',
1301+
alignItems: 'center',
1302+
pointerEvents: 'all'
1303+
};
1304+
1305+
Object.assign(overlay.style, styles);
1306+
overlay.innerHTML = '<div class="puter-loading-spinner">Working...</div>';
1307+
document.body.appendChild(overlay);
1308+
1309+
this.#overlayActive = true;
1310+
this.#overlayTimer = setTimeout(() => {
1311+
this.#overlayTimer = null;
1312+
}, 1000);
1313+
}
1314+
1315+
hideWorking() {
1316+
if (!this.#overlayActive) return;
1317+
1318+
if (this.#overlayTimer) {
1319+
clearTimeout(this.#overlayTimer);
1320+
this.#overlayTimer = null;
1321+
}
1322+
1323+
const overlay = document.querySelector('.puter-loading-overlay');
1324+
if (overlay) {
1325+
overlay.parentNode?.removeChild(overlay);
1326+
}
1327+
1328+
this.#overlayActive = false;
1329+
}
1330+
1331+
isWorkingActive() {
1332+
return this.#overlayActive;
1333+
}
12811334
}
12821335

12831336
export default UI

0 commit comments

Comments
 (0)