citadel-realms/js/model/Realm.js

95 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-11-12 17:12:37 -05:00
var _a;
import GObject from 'gi://GObject';
import { RealmFS } from './RealmFS.js';
import { RealmConfig } from './RealmConfig.js';
export const RunStatus = {
STOPPED: 0,
STARTING: 1,
RUNNING: 2,
CURRENT: 3,
STOPPING: 4,
};
export class Realm extends GObject.Object {
constructor(proxy, labelColors) {
super();
this.config = new RealmConfig();
this._proxy = proxy;
this._labelColors = labelColors;
this._proxy.connect('g-properties-changed', (_proxy, _changed, _invalidated) => {
this._sync();
});
this._sync();
}
get realmfs() {
return this._realmfs;
}
set realmfs(value) {
if (this.realmfs === value) {
return;
}
this._realmfs = value;
this.emit('changed');
}
_sync() {
this._name = this._proxy.Name;
this._description = this._proxy.Description;
this._pidns = this._proxy.PidNS;
this._run_status = this._proxy.RunStatus;
this._is_system_realm = this._proxy.IsSystemRealm;
this.emit('changed');
}
get name() {
return this._name;
}
get description() {
return this._description;
}
get pidns() {
return this._pidns;
}
get run_status() {
return this._run_status;
}
get is_system_realm() {
return this._is_system_realm;
}
is_running() {
return this.run_status === RunStatus.RUNNING || this.run_status === RunStatus.CURRENT;
}
is_current() {
return this.run_status === RunStatus.CURRENT;
}
getLabelColor() {
return this._labelColors.lookupRealmColor(this);
}
setLabelColor(color) {
this._labelColors.updateRealmColor(this, color);
}
realmfs_index() {
return this._proxy.RealmFS;
}
set_global_config(config) {
this.config.set_global_config(config);
}
async load_config() {
const result = await this._proxy.GetConfigAsync();
this.config.set_config(result[0]);
this.emit('changed');
}
}
_a = Realm;
(() => {
GObject.registerClass({
GTypeName: 'Realm',
Properties: {
'name': GObject.ParamSpec.string('name', '', '', GObject.ParamFlags.READWRITE, ''),
'description': GObject.ParamSpec.string('description', '', '', GObject.ParamFlags.READWRITE, ''),
'pidns': GObject.ParamSpec.uint64('pidns', '', '', GObject.ParamFlags.READWRITE, 0, Number.MAX_SAFE_INTEGER, 0),
'run-status': GObject.ParamSpec.uint('run-status', '', '', GObject.ParamFlags.READWRITE, 0, 4, 0),
'is-system-realm': GObject.ParamSpec.boolean('is-system-realm', '', '', GObject.ParamFlags.READWRITE, false),
'realmfs': GObject.ParamSpec.object('realmfs', '', '', GObject.ParamFlags.READWRITE, RealmFS),
},
Signals: { 'changed': {} },
}, _a);
})();