feat: Add safe mounting for display set viewers to enhance viewer initialization

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Ross
2026-04-28 14:56:43 +01:00
co-authored by Copilot
parent 68dfcdfa7e
commit 5c217266c4
@@ -96,6 +96,33 @@
if (!window.__displaysetPartialInitDone) {
window.__displaysetPartialInitDone = true;
if (typeof window.mountDisplaysetViewersSafely !== 'function') {
window.mountDisplaysetViewersSafely = async function () {
try {
await new Promise(function (resolve) {
requestAnimationFrame(function () {
requestAnimationFrame(resolve);
});
});
if (typeof window.mountDicomViewersSafely === 'function') {
await window.mountDicomViewersSafely();
} else if (typeof window.mountDicomViewers === 'function') {
window.mountDicomViewers();
}
requestAnimationFrame(function () {
try { window.dispatchEvent(new Event('resize')); } catch (e) {}
if (typeof window.resizeDicomViewers === 'function') {
try { window.resizeDicomViewers(); } catch (e) {}
}
});
} catch (e) {
console.warn('displayset viewer mount failed', e);
}
};
}
if (typeof window.loadDisplaysetModal !== 'function') {
window.loadDisplaysetModal = async function (url, dsId) {
if (!url && dsId) url = '/atlas/' + dsId + '/display_sets/modal';
@@ -118,6 +145,7 @@
}
bootstrap.Modal.getOrCreateInstance(modalEl).show();
await window.mountDisplaysetViewersSafely();
} catch (error) {
console.error('Error loading display set details:', error);
modalBody.innerHTML = '<p>Failed to load display set.</p>';
@@ -164,6 +192,7 @@
rightEl.innerHTML = tmp.innerHTML;
bootstrap.Modal.getOrCreateInstance(fullModalEl).show();
await window.mountDisplaysetViewersSafely();
} catch (error) {
console.error('Error loading fullscreen display set:', error);
leftEl.innerHTML = '<p style="color:#fff; padding:1rem;">Failed to load viewer</p>';