diff --git a/.github/workflows/windows-installer.yml b/.github/workflows/windows-installer.yml index 9084587..45a191a 100644 --- a/.github/workflows/windows-installer.yml +++ b/.github/workflows/windows-installer.yml @@ -11,7 +11,7 @@ on: release_version: description: "Version to publish (for example 1.0.3; do not include the v prefix)" required: true - default: "1.0.3" + default: "1.0.5" type: string permissions: @@ -41,7 +41,13 @@ jobs: } elseif ($env:GITHUB_REF -like "refs/tags/v*") { $version = $env:REF_NAME -replace '^v', '' } else { - $version = "1.0.3" + # Keep PR/push installer artifacts aligned with the version declared + # by the installer script instead of maintaining a second version. + $iss = Get-Content "installer/GLB-Viewer.iss" -Raw + if ($iss -notmatch '(?m)^\s*#define\s+AppVersion\s+"(\d+\.\d+\.\d+)"') { + throw "Could not resolve AppVersion from installer/GLB-Viewer.iss" + } + $version = $Matches[1] } if ($version -notmatch '^\d+\.\d+\.\d+$') { throw "Version must use the format X.Y.Z (received: $version)" diff --git a/installer/GLB-Viewer.iss b/installer/GLB-Viewer.iss index 5745546..2ae0232 100644 --- a/installer/GLB-Viewer.iss +++ b/installer/GLB-Viewer.iss @@ -1,6 +1,6 @@ #define AppName "GLB Viewer" #ifndef AppVersion - #define AppVersion "1.0.4" + #define AppVersion "1.0.5" #endif #define AppPublisher "VeloraTech" diff --git a/scripts/update-viewer.ps1 b/scripts/update-viewer.ps1 index 25c6372..03b748c 100644 --- a/scripts/update-viewer.ps1 +++ b/scripts/update-viewer.ps1 @@ -25,6 +25,7 @@ try { $assets = @( 'viewer.html', + 'src/editor/ViewerShell.js', 'src/editor/EditorStateStore.js', 'src/editor/ToolRegistry.js', 'src/editor/WorkspaceManager.js', @@ -34,6 +35,12 @@ try { 'src/editor/OrbitPreview.js', 'src/editor/ViewportWorkspace.js', 'src/editor/MultiObjectTransform.js', + 'three/examples/jsm/controls/OrbitControls.js', + 'three/examples/jsm/controls/TransformControls.js', + 'three/examples/jsm/environments/RoomEnvironment.js', + 'three/examples/jsm/loaders/GLTFLoader.js', + 'three/examples/jsm/utils/BufferGeometryUtils.js', + 'three/examples/jsm/exporters/GLTFExporter.js', 'src/core/ResourceDisposer.js', 'src/core/PerformanceMonitor.js', 'src/core/HardwareProviders.js', @@ -58,7 +65,7 @@ try { if ($asset -eq 'viewer.html' -and ($content -notmatch '' -or $content -notmatch 'GLB Viewer')) { throw 'Downloaded viewer.html failed its content check.' } - if ($asset.EndsWith('.js') -and $content -notmatch 'export ') { throw "Downloaded module failed its content check: $asset" } + if ($asset.EndsWith('.js') -and $asset -ne 'src/editor/ViewerShell.js' -and $content -notmatch 'export ') { throw "Downloaded module failed its content check: $asset" } } # Install as an immutable per-user version. The launcher reads the active diff --git a/src/editor/ViewerShell.js b/src/editor/ViewerShell.js new file mode 100644 index 0000000..d4e46a5 --- /dev/null +++ b/src/editor/ViewerShell.js @@ -0,0 +1,63 @@ +/* Independent viewer shell: this file intentionally has no ES-module dependencies. */ +(() => { + const state = { failed: false }; + function showBootstrapFailure(message) { + if (window.__GLB_VIEWER_BOOTED__ || state.failed) return; + state.failed = true; + const loading = document.getElementById('loading'); + if (loading) { + loading.classList.add('hidden'); + loading.style.display = 'none'; + } + const error = document.getElementById('error'); + if (error) { + error.style.display = 'none'; + error.style.pointerEvents = 'none'; + } + let notice = document.getElementById('viewer-bootstrap-error'); + if (!notice) { + notice = document.createElement('div'); + notice.id = 'viewer-bootstrap-error'; + notice.setAttribute('role', 'alert'); + notice.style.cssText = 'position:fixed;left:12px;top:58px;z-index:200;max-width:min(560px,calc(100vw - 24px));padding:12px 14px;border:1px solid rgba(255,120,120,.45);border-radius:8px;background:#282326;color:#fff;font:13px/1.5 system-ui,sans-serif;box-shadow:0 8px 28px rgba(0,0,0,.35);pointer-events:auto'; + document.body.appendChild(notice); + } + notice.textContent = 'Viewer tools could not finish initializing. Your workspace navigation is still available. ' + message; + console.error('[GLB Viewer bootstrap]', message); + } + window.addEventListener('error', event => { + const target = event.target; + if (target && (target.tagName === 'SCRIPT' || target.tagName === 'LINK')) { + const assetUrl = target.src || target.href || ''; + // Third-party icon CDN failures must never disable the local application. + if (assetUrl && new URL(assetUrl, window.location.href).origin !== window.location.origin) return; + if (assetUrl) showBootstrapFailure('A required local application file failed to load: ' + assetUrl); + return; + } + if (event.error) showBootstrapFailure(event.error.message || 'An application startup error occurred.'); + }, true); + window.addEventListener('unhandledrejection', event => { + showBootstrapFailure(event.reason?.message || 'An application startup task failed.'); + }); + document.addEventListener('click', event => { + if (window.__GLB_VIEWER_BOOTED__) return; + const button = event.target.closest?.('[data-workspace]'); + if (!button) return; + const name = button.dataset.workspace; + const shell = document.getElementById('workspace-main'); + const content = document.getElementById('workspace-content'); + if (!shell || !content) return; + const views = [...content.querySelectorAll('.workspace-view')]; + const selected = views.find(view => view.dataset.view === name); + if (!selected) return; + shell.hidden = false; + shell.style.display = 'flex'; + views.forEach(view => { view.hidden = view !== selected; }); + const heading = shell.querySelector('#workspace-header h2'); + if (heading) heading.textContent = name[0].toUpperCase() + name.slice(1); + button.classList.add('active'); + document.querySelectorAll('[data-workspace]').forEach(item => { + if (item !== button) item.classList.remove('active'); + }); + }); +})(); diff --git a/tests/viewer-resilience.test.js b/tests/viewer-resilience.test.js new file mode 100644 index 0000000..90f63e9 --- /dev/null +++ b/tests/viewer-resilience.test.js @@ -0,0 +1,32 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import { existsSync } from 'node:fs'; + +const viewer = await readFile(new URL('../viewer.html', import.meta.url), 'utf8'); +const updater = await readFile(new URL('../scripts/update-viewer.ps1', import.meta.url), 'utf8'); +const shell = await readFile(new URL('../src/editor/ViewerShell.js', import.meta.url), 'utf8'); + +test('every local Three.js addon statically imported by the viewer is bundled', () => { + const imports = [...viewer.matchAll(/from\s+['"]three\/addons\/([^'"]+)['"]/g)].map(match => match[1]); + assert.ok(imports.length > 0, 'expected local Three.js addon imports'); + for (const path of imports) { + assert.ok(existsSync(new URL('../three/examples/jsm/' + path, import.meta.url)), 'missing bundled addon: ' + path); + assert.ok(updater.includes("'three/examples/jsm/" + path + "'"), 'updater does not deliver addon: ' + path); + } +}); + +test('independent shell loads before the application module', () => { + const shellPosition = viewer.indexOf(''); + const modulePosition = viewer.indexOf(' + +