2012-08-19 21:37:54 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
|
|
|
const ProviderIface = loadInterfaceXML("org.freedesktop.realmd.Provider");
|
2012-08-19 21:37:54 -04:00
|
|
|
const Provider = Gio.DBusProxy.makeProxyWrapper(ProviderIface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const ServiceIface = loadInterfaceXML("org.freedesktop.realmd.Service");
|
2012-08-19 21:37:54 -04:00
|
|
|
const Service = Gio.DBusProxy.makeProxyWrapper(ServiceIface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const RealmIface = loadInterfaceXML("org.freedesktop.realmd.Realm");
|
2012-08-19 21:37:54 -04:00
|
|
|
const Realm = Gio.DBusProxy.makeProxyWrapper(RealmIface);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var Manager = class {
|
2019-02-04 06:30:53 -05:00
|
|
|
constructor() {
|
2012-08-19 21:37:54 -04:00
|
|
|
this._aggregateProvider = Provider(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2019-01-28 20:18:52 -05:00
|
|
|
this._reloadRealms.bind(this));
|
2012-08-19 21:37:54 -04:00
|
|
|
this._realms = {};
|
2019-05-23 00:12:56 -04:00
|
|
|
this._loginFormat = null;
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
this._aggregateProvider.connectObject('g-properties-changed',
|
2017-10-30 20:38:18 -04:00
|
|
|
(proxy, properties) => {
|
|
|
|
if ('Realms' in properties.deep_unpack())
|
|
|
|
this._reloadRealms();
|
2021-08-15 18:36:59 -04:00
|
|
|
}, this);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadRealms() {
|
2012-08-19 21:37:54 -04:00
|
|
|
let realmPaths = this._aggregateProvider.Realms;
|
|
|
|
|
|
|
|
if (!realmPaths)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < realmPaths.length; i++) {
|
2019-01-31 09:04:56 -05:00
|
|
|
Realm(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
realmPaths[i],
|
|
|
|
this._onRealmLoaded.bind(this));
|
2012-08-19 21:37:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadRealm(realm) {
|
2012-08-19 21:37:54 -04: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-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onRealmLoaded(realm, error) {
|
2012-08-19 21:37:54 -04:00
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
realm.connect('g-properties-changed', (proxy, properties) => {
|
|
|
|
if ('Configured' in properties.deep_unpack())
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateLoginFormat() {
|
2012-08-19 21:37:54 -04: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-30 21:19:44 -04:00
|
|
|
}
|
2012-08-19 21:37:54 -04:00
|
|
|
|
|
|
|
get loginFormat() {
|
2019-05-23 00:12:56 -04:00
|
|
|
if (this._loginFormat)
|
2012-08-19 21:37:54 -04:00
|
|
|
return this._loginFormat;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
|
|
|
|
|
|
|
return this._loginFormat;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-04-19 03:07:04 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
release() {
|
2013-04-19 03:07:04 -04:00
|
|
|
Service(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2019-01-27 19:42:00 -05:00
|
|
|
service => service.ReleaseRemote());
|
2021-08-15 18:36:59 -04:00
|
|
|
this._aggregateProvider.disconnectObject(this);
|
2013-04-19 03:07:04 -04:00
|
|
|
this._realms = { };
|
|
|
|
this._updateLoginFormat();
|
2012-08-19 21:37:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2019-01-28 20:18:52 -05:00
|
|
|
Signals.addSignalMethods(Manager.prototype);
|