1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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"); });
}
}
|