95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
|
import { OptionData } from './OptionData.js';
|
||
|
export class BoolOptionData {
|
||
|
constructor(name) {
|
||
|
var _a, _b;
|
||
|
this.name = name;
|
||
|
this.description = (_a = OptionData.description(name)) !== null && _a !== void 0 ? _a : name;
|
||
|
this.tooltip = (_b = OptionData.tooltip(name)) !== null && _b !== void 0 ? _b : "";
|
||
|
}
|
||
|
static allOptions() {
|
||
|
let options = [];
|
||
|
BoolOptionData.ALL_OPTIONS.forEach(name => {
|
||
|
options.push(new BoolOptionData(name));
|
||
|
});
|
||
|
return options;
|
||
|
}
|
||
|
}
|
||
|
BoolOptionData.ALL_OPTIONS = [
|
||
|
'use-gpu',
|
||
|
'use-wayland',
|
||
|
'use-x11',
|
||
|
'use-sound',
|
||
|
'use-network',
|
||
|
'use-kvm',
|
||
|
'use-shared-dir',
|
||
|
'use-ephemeral-home',
|
||
|
];
|
||
|
export class ConfigOption {
|
||
|
constructor(name, value, defaultValue, description, tooltip) {
|
||
|
this.name = name;
|
||
|
this.value = value;
|
||
|
this.defaultValue = defaultValue;
|
||
|
this.description = description;
|
||
|
this.tooltip = tooltip;
|
||
|
}
|
||
|
}
|
||
|
export class RealmConfig {
|
||
|
constructor() {
|
||
|
this._configVars = {};
|
||
|
this._globalConfig = {};
|
||
|
}
|
||
|
set_config(config) {
|
||
|
this._configVars = config;
|
||
|
}
|
||
|
set_global_config(globalConfig) {
|
||
|
this._globalConfig = globalConfig;
|
||
|
}
|
||
|
get_var(name) {
|
||
|
let value = this._configVars[name];
|
||
|
if (value && value.length > 0) {
|
||
|
return value;
|
||
|
}
|
||
|
value = this._globalConfig[name];
|
||
|
if (value && value.length > 0) {
|
||
|
return value;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
get_bool(name) {
|
||
|
return this.get_var(name) === 'true';
|
||
|
}
|
||
|
get_colorscheme() {
|
||
|
var _a;
|
||
|
return (_a = this.get_var('terminal-scheme')) !== null && _a !== void 0 ? _a : 'default-dark';
|
||
|
}
|
||
|
get_realmfs() {
|
||
|
var _a;
|
||
|
return (_a = this.get_var('realmfs')) !== null && _a !== void 0 ? _a : 'base';
|
||
|
}
|
||
|
static capitalize(term) {
|
||
|
const acronyms = ["gpu", "kvm"];
|
||
|
if (acronyms.find(s => term === s)) {
|
||
|
return term.toUpperCase();
|
||
|
}
|
||
|
else {
|
||
|
return term.charAt(0).toUpperCase() + term.slice(1);
|
||
|
}
|
||
|
}
|
||
|
static option_label(key) {
|
||
|
return key.substring(4)
|
||
|
.split('-')
|
||
|
.map(RealmConfig.capitalize)
|
||
|
.join('');
|
||
|
}
|
||
|
is_enabled_bool_option(name, value, isDefault) {
|
||
|
const default_val = this._globalConfig[name];
|
||
|
return name.startsWith("use-") && value === "true" && (value === default_val) === isDefault;
|
||
|
}
|
||
|
enabled_bool_option_labels(isDefault) {
|
||
|
return Object.entries(this._configVars)
|
||
|
.filter(([k, v]) => this.is_enabled_bool_option(k, v, isDefault))
|
||
|
.map(([k,]) => RealmConfig.option_label(k))
|
||
|
.sort();
|
||
|
}
|
||
|
}
|