gnome-shell/js/ui/realms/realmIndicator.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-12-03 19:04:05 +00:00
const { Clutter, GObject, Shell, St } = imports.gi;
const PanelMenu = imports.ui.panelMenu;
var RealmPanelIndicator = GObject.registerClass(
class RealmPanelIndicator extends PanelMenu.Button {
_init() {
super._init(0.5, "Current Realm");
this._label = new St.Label({
style_class: 'current-realm-label',
y_align: Clutter.ActorAlign.CENTER
});
this.add_child(this._label);
this.update();
}
clear() {
this._label.set_text('');
}
update() {
let realm_name = '';
const realms = Shell.Realms.get_default();
let current = realms.current_realm;
if (current) {
realm_name = current.realm_name;
this._label.set_text(`realm-${realm_name}`);
}
if (realm_name.length > 0) {
this._label.set_text(`realm-${realm_name}`);
} else {
this._label.set_text('');
}
}
});