// Extracted from newOS4 index.html — ModuleIOModule class ModuleIOModule { constructor() { this.commands = {}; this.terminal = null; } getHelpInfo() { return { 'export-mods': 'export-mods — Export all loaded modules to a JSON file', 'import-mods': 'import-mods — Import modules from a JSON file', 'backup': 'backup — Create a full system backup', 'restore': 'restore — Restore system from a backup file', 'share-mod': 'share-mod — Share a module as JSON to clipboard' }; } registerCommands() { this.commands['export-mods'] = () => this.exportModules(); this.commands['import-mods'] = (args) => this.importModules(args); this.commands['backup'] = () => this.fullBackup(); this.commands['restore'] = (args) => this.restoreBackup(args); this.commands['share-mod'] = (args) => this.shareModule(args); } exportModules() { const registry = this.terminal.moduleManager.moduleRegistry; if (registry.length === 0) { this.terminal.print("No modules to export", "warning"); return; } const exportData = { version: '4.1', exported: new Date().toISOString(), modules: registry }; const json = JSON.stringify(exportData, null, 2); const blob = new Blob([json], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `webx11-modules-${Date.now()}.json`; a.click(); URL.revokeObjectURL(url); this.terminal.print(`Exported ${registry.length} module(s)`, "success"); } importModules(args) { this.terminal.print("⚠️ To import modules:", "warning"); this.terminal.print("1. Upload the JSON file using 'upload'", "info"); this.terminal.print("2. Use: import-mods ", "info"); } async fullBackup() { const backup = { version: '4.1', timestamp: new Date().toISOString(), filesystem: localStorage.getItem('webx11_filesystem'), modules: localStorage.getItem('webx11_modules'), ollama: { endpoint: localStorage.getItem('webx11_ollama_endpoint'), model: localStorage.getItem('webx11_ollama_model') }, config: {} }; for (let i = 0; i < localStorage.length; i++) { const key = localStorage.key(i); if (key.startsWith('webx11_')) { backup.config[key] = localStorage.getItem(key); } } const json = JSON.stringify(backup, null, 2); const blob = new Blob([json], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `webx11-backup-${Date.now()}.json`; a.click(); URL.revokeObjectURL(url); this.terminal.print("Full backup created", "success"); } restoreBackup(args) { this.terminal.print("⚠️ To restore backup:", "warning"); this.terminal.print("1. Upload the backup JSON file", "info"); this.terminal.print("2. Use: restore ", "info"); } shareModule(args) { if (!args[0]) { this.terminal.print("Usage: share-mod ", "warning"); return; } const mod = this.terminal.moduleManager.moduleRegistry.find(m => m.name === args[0]); if (!mod) { this.terminal.print(`Module '${args[0]}' not found`, "error"); return; } const shareData = { name: mod.name, url: mod.url, shared: new Date().toISOString() }; const json = JSON.stringify(shareData, null, 2); navigator.clipboard.writeText(json).then(() => { this.terminal.print("Module info copied to clipboard", "success"); }).catch(() => { this.terminal.print(json, "info"); }); } }