// Extracted from newOS4 index.html — ConfigManagerModule
class ConfigManagerModule {
constructor() {
this.commands = {}; this.terminal = null;
this.configPrefix = 'webx11_config_';
}
getHelpInfo() {
return {
'config': 'config [key] — Show all config or a specific key',
'config-set': 'config-set — Set a configuration value',
'config-list': 'config-list — List all configuration keys',
'config-delete': 'config-delete — Delete a configuration key',
'config-export': 'config-export — Export all config as JSON',
'config-reset': 'config-reset — Reset all configuration to defaults',
};
}
registerCommands() {
this.commands['config'] = (args) => this.getConfig(args);
this.commands['config-set'] = (args) => this.setConfig(args);
this.commands['config-list'] = () => this.listConfig();
this.commands['config-delete'] = (args) => this.deleteConfig(args);
this.commands['config-export'] = () => this.exportConfig();
this.commands['config-reset'] = () => this.resetConfig();
}
getConfig(args) {
if (!args[0]) {
this.terminal.print("Usage: config ", "warning"); return;
}
const value = localStorage.getItem(this.configPrefix + args[0]);
if (value) {
this.terminal.print(`${args[0]}: ${value}`, "info");
} else {
this.terminal.print(`Key '${args[0]}' not found`, "error");
}
}
setConfig(args) {
if (args.length < 2) {
this.terminal.print("Usage: config-set ", "warning"); return;
}
const key = args[0], value = args.slice(1).join(' ');
localStorage.setItem(this.configPrefix + key, value);
this.terminal.print(`Config saved: ${key} = ${value}`, "success");
}
listConfig() {
const configs = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith(this.configPrefix)) {
configs[key.replace(this.configPrefix, '')] = localStorage.getItem(key);
}
}
if (Object.keys(configs).length === 0) {
this.terminal.print("No configuration saved", "info"); return;
}
this.terminal.print("=== Configuration ===", "info");
Object.entries(configs).forEach(([k, v]) => { this.terminal.print(`${k}: ${v}`); });
}
deleteConfig(args) {
if (!args[0]) {
this.terminal.print("Usage: config-delete ", "warning"); return;
}
localStorage.removeItem(this.configPrefix + args[0]);
this.terminal.print(`Config '${args[0]}' deleted`, "success");
}
exportConfig() {
const configs = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith(this.configPrefix)) {
configs[key] = localStorage.getItem(key);
}
}
const json = JSON.stringify(configs, 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-config.json'; a.click();
URL.revokeObjectURL(url);
this.terminal.print("Configuration exported", "success");
}
resetConfig() {
if (confirm("Reset all configuration to defaults?")) {
const keysToRemove = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith(this.configPrefix)) { keysToRemove.push(key); }
}
keysToRemove.forEach(k => localStorage.removeItem(k));
this.terminal.print("Configuration reset to defaults", "success");
}
}
}