2012-08-20 01:37:54 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import * as Signals from '../misc/signals.js';
|
2012-08-20 01:37:54 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import {loadInterfaceXML} from '../misc/fileUtils.js';
|
2018-09-06 00:55:20 +00:00
|
|
|
|
|
|
|
const ProviderIface = loadInterfaceXML("org.freedesktop.realmd.Provider");
|
2012-08-20 01:37:54 +00:00
|
|
|
const Provider = Gio.DBusProxy.makeProxyWrapper(ProviderIface);
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const ServiceIface = loadInterfaceXML("org.freedesktop.realmd.Service");
|
2012-08-20 01:37:54 +00:00
|
|
|
const Service = Gio.DBusProxy.makeProxyWrapper(ServiceIface);
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const RealmIface = loadInterfaceXML("org.freedesktop.realmd.Realm");
|
2012-08-20 01:37:54 +00:00
|
|
|
const Realm = Gio.DBusProxy.makeProxyWrapper(RealmIface);
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export class Manager extends Signals.EventEmitter {
|
2019-02-04 11:30:53 +00:00
|
|
|
constructor() {
|
2022-07-04 22:30:44 +00:00
|
|
|
super();
|
|
|
|
|
2012-08-20 01:37:54 +00:00
|
|
|
this._aggregateProvider = Provider(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2019-01-29 01:18:52 +00:00
|
|
|
this._reloadRealms.bind(this));
|
2012-08-20 01:37:54 +00:00
|
|
|
this._realms = {};
|
2019-05-23 04:12:56 +00:00
|
|
|
this._loginFormat = null;
|
2012-08-20 01:37:54 +00:00
|
|
|
|
2021-08-15 22:36:59 +00:00
|
|
|
this._aggregateProvider.connectObject('g-properties-changed',
|
2017-10-31 00:38:18 +00:00
|
|
|
(proxy, properties) => {
|
2022-08-10 09:44:42 +00:00
|
|
|
const realmsChanged = !!properties.lookup_value('Realms', null);
|
|
|
|
if (realmsChanged)
|
2017-10-31 00:38:18 +00:00
|
|
|
this._reloadRealms();
|
2021-08-15 22:36:59 +00:00
|
|
|
}, this);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-20 01:37:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_reloadRealms() {
|
2012-08-20 01:37:54 +00:00
|
|
|
let realmPaths = this._aggregateProvider.Realms;
|
|
|
|
|
|
|
|
if (!realmPaths)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < realmPaths.length; i++) {
|
2019-01-31 14:04:56 +00:00
|
|
|
Realm(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
realmPaths[i],
|
|
|
|
this._onRealmLoaded.bind(this));
|
2012-08-20 01:37:54 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-20 01:37:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_reloadRealm(realm) {
|
2012-08-20 01:37:54 +00:00
|
|
|
if (!realm.Configured) {
|
|
|
|
if (this._realms[realm.get_object_path()])
|
|
|
|
delete this._realms[realm.get_object_path()];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._realms[realm.get_object_path()] = realm;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-20 01:37:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onRealmLoaded(realm, error) {
|
2012-08-20 01:37:54 +00:00
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
realm.connect('g-properties-changed', (proxy, properties) => {
|
2022-08-10 09:44:42 +00:00
|
|
|
const configuredChanged = !!properties.lookup_value('Configured', null);
|
|
|
|
if (configuredChanged)
|
2017-10-31 00:38:18 +00:00
|
|
|
this._reloadRealm(realm);
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-20 01:37:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateLoginFormat() {
|
2012-08-20 01:37:54 +00:00
|
|
|
let newLoginFormat;
|
|
|
|
|
|
|
|
for (let realmPath in this._realms) {
|
|
|
|
let realm = this._realms[realmPath];
|
|
|
|
if (realm.LoginFormats && realm.LoginFormats.length > 0) {
|
|
|
|
newLoginFormat = realm.LoginFormats[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._loginFormat != newLoginFormat) {
|
|
|
|
this._loginFormat = newLoginFormat;
|
|
|
|
this.emit('login-format-changed', newLoginFormat);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-20 01:37:54 +00:00
|
|
|
|
|
|
|
get loginFormat() {
|
2019-05-23 04:12:56 +00:00
|
|
|
if (this._loginFormat)
|
2012-08-20 01:37:54 +00:00
|
|
|
return this._loginFormat;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
|
|
|
|
|
|
|
return this._loginFormat;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-19 07:07:04 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
release() {
|
2013-04-19 07:07:04 +00:00
|
|
|
Service(Gio.DBus.system,
|
2022-06-23 12:53:29 +00:00
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
|
|
|
service => service.ReleaseAsync().catch(logError));
|
2021-08-15 22:36:59 +00:00
|
|
|
this._aggregateProvider.disconnectObject(this);
|
2013-04-19 07:07:04 +00:00
|
|
|
this._realms = { };
|
|
|
|
this._updateLoginFormat();
|
2012-08-20 01:37:54 +00:00
|
|
|
}
|
2023-07-10 09:53:00 +00:00
|
|
|
}
|