aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-io.js
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-05-25 18:02:02 +0200
committerAgando <roduccomm@gmail.com>2026-05-25 18:02:02 +0200
commit4baa484b84c5184286cac2743575251454a5ee2b (patch)
treecb9002f93644f363d0f35831dc97e6492bbb0ed6 /modules/core/module-io.js
auto: 2026-05-25_18:02 changes
Diffstat (limited to 'modules/core/module-io.js')
-rw-r--r--modules/core/module-io.js80
1 files changed, 80 insertions, 0 deletions
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 <filename> — Import modules from a JSON file',
+ 'backup': 'backup — Create a full system backup',
+ 'restore': 'restore <filename> — Restore system from a backup file',
+ 'share-mod': 'share-mod <module-name> — 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 <filename>", "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 <filename>", "info");
+ }
+ shareModule(args) {
+ if (!args[0]) {
+ this.terminal.print("Usage: share-mod <module-name>", "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"); });
+ }
+ }