diff options
Diffstat (limited to 'modules/core/module-loader.js')
| -rw-r--r-- | modules/core/module-loader.js | 167 |
1 files changed, 24 insertions, 143 deletions
diff --git a/modules/core/module-loader.js b/modules/core/module-loader.js index 0261256..e0fa8e1 100644 --- a/modules/core/module-loader.js +++ b/modules/core/module-loader.js @@ -1,76 +1,14 @@ (function() { 'use strict'; - const BASE = 'modules/core/'; + // Core module bundle loaded synchronously in main.html. + // This loader only handles version cache-busting, splash, terminal init, and optional ext modules. - const FOUNDATION = [ - 'virtual-fs.js', - 'module-manager.js', - 'ollama-manager.js', - 'terminal.js' - ]; - - const BUILTIN = [ - 'module-system.js', - 'module-fs.js', - 'module-ollama.js', - 'module-my.js', - 'module-modmgr.js', - 'module-searxng.js', - 'module-servermon.js', - 'module-config.js', - 'module-simplegui.js', - 'module-io.js', - 'module-dynamicprompts.js', - 'module-aiassist.js', - 'module-aiasm.js', - 'module-smartctx.js', - 'module-duckduckgo.js', - 'module-fetcher.js', - 'secret-vault.js', - 'module-chatstudio.js', - 'module-agent-registry.js', - 'module-leases.js', - 'module-orchestrator.js', - 'module-sandbox.js', - 'module-memory-graph.js', - 'module-predictor.js', - 'module-world-model.js', - 'module-neural-vfs.js' - ]; - - function getSelectedModules() { - try { - const saved = localStorage.getItem('webx11_startup_modules'); - if (!saved) return null; - const parsed = JSON.parse(saved); - if (Array.isArray(parsed)) return parsed; - } catch (e) {} - return null; - } - - function isSelected(name, selected) { - if (!selected) return true; - return selected.includes(name); - } - - function loadScript(url, filename) { - return new Promise((resolve) => { - const existing = document.querySelector(`script[src="${url}"]`); - if (existing) { resolve(); return; } - const el = document.createElement('script'); - el.src = url + (url.includes('?') ? '&t=' : '?t=') + Date.now(); - el.onload = () => resolve(); - el.onerror = () => { - console.warn(`[ModuleLoader] Failed to load: ${filename || url} — continuing`); - // Log to terminal if available - if (typeof window !== 'undefined' && window.webx11 && window.webx11.log) { - window.webx11.log('WARN', 'Loader', 'Failed to load: ' + (filename || url)); - } - resolve(); - }; - document.body.appendChild(el); - }); + const LATEST_VER = '2026-06-13-v4.5.49'; + const CACHE = '?v=' + LATEST_VER; + const stored = localStorage.getItem('webx11_cache_ver'); + if (stored !== LATEST_VER) { + localStorage.setItem('webx11_cache_ver', LATEST_VER); } function setSplash(phase, current, total, filename) { @@ -99,94 +37,37 @@ if (fill) fill.style.background = 'var(--error-color)'; } - function reloadWithSelection() { - location.reload(); - } - - window.__moduleLoaderReload = reloadWithSelection; - - const LATEST_VER = '2026-06-11-v4.5.45'; - const CACHE = '?v=' + LATEST_VER; - const stored = localStorage.getItem('webx11_cache_ver'); - if (stored !== LATEST_VER) { - localStorage.setItem('webx11_cache_ver', LATEST_VER); - } - async function init() { try { - const selected = getSelectedModules(); - const total = FOUNDATION.length + BUILTIN.length; + const total = 3; let count = 0; - // Phase 1: Foundation (always load) - setSplash('Loading foundation layer (1/3)', 0, total, ''); - for (const mod of FOUNDATION) { - count++; - setSplash('Loading foundation layer (1/3)', count, total, mod); - await loadScript(BASE + mod + CACHE, mod); - } - - // Phase 2: Built-in modules (filtered) - setSplash('Loading built-in modules (2/3)', count, total, ''); - // v4.5.43: Get disabled modules from localStorage (set by module-disable command) - let disabledMods = []; - try { disabledMods = JSON.parse(localStorage.getItem('webx11_module_disabled') || '[]'); } catch (e) {} + setSplash('Core bundle loaded (1/3)', ++count, total, 'core-bundle.js'); + setSplash('Critical ext bundle loaded (2/3)', ++count, total, 'critical-ext-bundle.js'); - for (const mod of BUILTIN) { - count++; - if (!isSelected(mod, selected)) { - console.log(`[ModuleLoader] Skipped: ${mod} (not in startup selection)`); - setSplash('Loading built-in modules (2/3)', count, total, '⏭ ' + mod); - await new Promise(r => setTimeout(r, 20)); - continue; - } - // v4.5.43: Skip disabled modules - const modName = mod.replace(/\.js$/, ''); - if (disabledMods.includes(modName)) { - console.log(`[ModuleLoader] Skipped: ${mod} (disabled via module-disable)`); - setSplash('Loading built-in modules (2/3)', count, total, '⊘ ' + mod); - await new Promise(r => setTimeout(r, 20)); - continue; - } - setSplash('Loading built-in modules (2/3)', count, total, mod); - await loadScript(BASE + mod + CACHE, mod); - } - - // Phase 3: Initialize terminal setSplash('Initializing terminal (3/3)', total, total, ''); const webx11 = new WebX11Terminal(); window.webx11 = webx11; - // Auto-connect to Ollama after init - setTimeout(async () => { - try { - if (webx11.ollamaManager && !webx11.ollamaManager.connected) { - webx11.log('INFO', 'System', 'WebX11 ' + (window.NEWOS4_VERSION || 'v4.0') + ' started'); - webx11.log('INFO', 'System', 'Default model: ' + webx11.ollamaManager.currentModel); - await webx11.ollamaManager.connect(); - if (typeof webx11.updateOllamaStatus === 'function') { - webx11.updateOllamaStatus(); - } - webx11.print('🤖 Default model: ' + webx11.ollamaManager.currentModel, 'info'); - } - } catch (e) { - // Silently ignore — user can manually connect - } - }, 500); - - // Phase 4: Ext modules (filtered) + // Optional ext modules via packages.json if (typeof webx11._loadExtModules === 'function') { - const extKeys = ['calc', 'voice', 'cron', 'theme', 'wpm', 'mindmap', 'webdav', 'skill-pack-core', 'editor', 'diff', 'alias', 'finder', 'filemgr', 'cryptogzip', 'tutorial', 'shell', 'busybox', 'floating', 'console']; - const extSelected = selected - ? extKeys.filter(k => isSelected(k + '.js', selected)) - : extKeys; - if (extSelected.length > 0) { - webx11._loadExtModules(extSelected); + const extKeys = ['calc', 'voice', 'cron', 'theme', 'wpm', 'mindmap', 'webdav', 'skill-pack-core', 'cryptogzip', 'tutorial', 'floating', 'console']; + const saved = localStorage.getItem('webx11_startup_modules'); + let selected = null; + try { if (saved) selected = JSON.parse(saved); } catch (e) {} + if (selected && Array.isArray(selected)) { + extKeys = extKeys.filter(k => selected.includes(k + '.js')); + } + let disabledMods = []; + try { disabledMods = JSON.parse(localStorage.getItem('webx11_module_disabled') || '[]'); } catch (e) {} + extKeys = extKeys.filter(k => !disabledMods.includes(k)); + if (extKeys.length > 0) { + setTimeout(() => webx11._loadExtModules(extKeys), 800); } } hideSplash(); - console.log('[ModuleLoader] All modules loaded successfully'); + console.log('[ModuleLoader] Core loader initialized'); } catch (err) { console.error('[ModuleLoader] Fatal error:', err); showSplashError('Loading failed — ' + err.message); |