From 4baa484b84c5184286cac2743575251454a5ee2b Mon Sep 17 00:00:00 2001 From: Agando Date: Mon, 25 May 2026 18:02:02 +0200 Subject: auto: 2026-05-25_18:02 changes --- modules/core/module-io.js | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules/core/module-io.js (limited to 'modules/core/module-io.js') diff --git a/modules/core/module-io.js b/modules/core/module-io.js new file mode 100644 index 0000000..d7ff996 --- /dev/null +++ b/modules/core/module-io.js @@ -0,0 +1,80 @@ +// 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"); }); + } + } -- cgit v1.2.3