Fix CMMS-embedded loads freezing on the boot curtain forever

restore_space() (the normal boot path, restoring a previous IndexedDB
session) is intentionally skipped for a CMMS-scoped launch - but its
finalization tail (hide the loading curtain via boot_done(), enable
handles, publish app_ready) only ever ran inside restore_space() itself.
Skipping it meant the curtain never went away even after cmms_load_from_url
fetched and loaded the file successfully underneath it. app_ready
subscribers never fired either - mesh/history.js's undo-tracking enable,
mesh/build.js's doc-name label - a second, less visible bug from the same
cause.

Wrapped in try/finally so this always runs, even on a failed fetch -
a file that can't load shouldn't leave the user stuck behind the
curtain either. Also calls api.document.restoreOrCreate() first, since
restore_space() always does that before any file-load in normal use.
This commit is contained in:
AI Assistant 2026-08-27 20:15:28 +10:00
commit cda1d784ff

View file

@ -768,15 +768,35 @@ function space_init(data) {
// fetched Blob wrapped in a File object looks identical to one the user
// picked, so no new parsing/import logic is needed here at all.
async function cmms_load_from_url(config) {
const response = await fetch(config.loadUrl);
if (!response.ok) {
log(`CMMS load failed: HTTP ${response.status}`).pin({});
return;
// restore_space() (the normal boot path) is intentionally skipped for a
// CMMS-scoped launch (this loads one specific file, not whatever was
// last open in this browser - see init()'s own comment above) - but its
// finalization tail (hide the loading curtain, enable handles, publish
// app_ready) only ever runs inside restore_space() itself, so skipping
// it meant the curtain never went away even after the file loaded fine
// underneath it (CMMS bug report, 2026-08-27: froze on the loading
// curtain despite attachment.php's fetch succeeding). app_ready
// subscribers never fired either - mesh/history.js's undo-tracking
// enable, mesh/build.js's doc-name label. try/finally so this always
// happens, even if the fetch or file itself fails - a file that can't
// load shouldn't leave the user stuck behind the curtain either.
try {
const response = await fetch(config.loadUrl);
if (!response.ok) {
log(`CMMS load failed: HTTP ${response.status}`).pin({});
return;
}
const buf = await response.arrayBuffer();
const name = config.originalName || 'attachment.stl';
const file = new File([buf], name, { type: 'application/octet-stream' });
await api.document.restoreOrCreate();
load_files([file]);
} finally {
boot_done();
handles.setEnabled(api.prefs.map.space.bounds ?? false);
api.file.set_doc_name(config.originalName || 'Untitled');
broker.publish("app_ready");
}
const buf = await response.arrayBuffer();
const name = config.originalName || 'attachment.stl';
const file = new File([buf], name, { type: 'application/octet-stream' });
load_files([file]);
}
function load_files(files) {