36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
async function loadWorkspace({ document, window = null, createLoader = createFeatureLoader }) {
|
|
let cameOnline = false;
|
|
let replayed = false;
|
|
const captureOnline = () => { cameOnline = true; };
|
|
window?.addEventListener('online', captureOnline);
|
|
const status = document.querySelector('#my-work-action-status');
|
|
const url = document.querySelector(
|
|
'meta[name="stackchain-feature-today-timer"]'
|
|
)?.content || '';
|
|
const loader = createLoader({
|
|
document,
|
|
urls: { 'today-timer': url },
|
|
});
|
|
if (status) status.textContent = 'Starting workspace…';
|
|
try {
|
|
await loader.load('today-timer');
|
|
if (status) status.textContent = '';
|
|
return {
|
|
replayOnline(callback) {
|
|
if (replayed) return;
|
|
replayed = true;
|
|
window?.removeEventListener('online', captureOnline);
|
|
if (cameOnline) callback();
|
|
},
|
|
};
|
|
} catch (error) {
|
|
window?.removeEventListener('online', captureOnline);
|
|
if (status) {
|
|
status.textContent =
|
|
'Workspace could not load. Check your connection, then reload to retry.';
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
if (typeof module !== 'undefined' && module.exports) module.exports = loadWorkspace; |