@@ -162,6 +162,9 @@ class UI extends EventListener {
162
162
// The most recent value that we received for a given broadcast, by name.
163
163
#lastBroadcastValue = new Map ( ) ; // name -> data
164
164
165
+ #overlayActive = false ;
166
+ #overlayTimer = null ;
167
+
165
168
// Replaces boilerplate for most methods: posts a message to the GUI with a unique ID, and sets a callback for it.
166
169
#postMessageWithCallback = function ( name , resolve , args = { } ) {
167
170
const msg_id = this . #messageID++ ;
@@ -1278,6 +1281,56 @@ class UI extends EventListener {
1278
1281
callback ( this . #lastBroadcastValue. get ( eventName ) ) ;
1279
1282
}
1280
1283
}
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
+ }
1281
1334
}
1282
1335
1283
1336
export default UI
0 commit comments