js: Use async D-Bus wrappers

After porting the more complex cases - in particular those that
affect a module's API - we are left with straight-forward D-Bus
method calls that can be moved to promise-based wrappers in one
go.

For consistency, this also switches from Remote to Async where
the call result is ignored.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2344>
This commit is contained in:
Florian Müllner
2022-06-23 14:53:29 +02:00
committed by Marge Bot
parent a3db909383
commit 637ee7386e
23 changed files with 462 additions and 496 deletions

View File

@ -153,24 +153,24 @@ class ModemGsm extends ModemBase {
this._proxy.connectSignal('RegistrationInfo', (proxy, sender, [_status, code, name]) => {
this._setOperatorName(_findProviderForMccMnc(name, code));
});
this._proxy.GetRegistrationInfoRemote(([result], err) => {
if (err) {
log(err);
return;
}
this._getInitialState();
}
let [status_, code, name] = result;
async _getInitialState() {
try {
const [
[status_, code, name],
[quality],
] = await Promise.all([
this._proxy.GetRegistrationInfoAsync(),
this._proxy.GetSignalQualityAsync(),
]);
this._setOperatorName(_findProviderForMccMnc(name, code));
});
this._proxy.GetSignalQualityRemote((result, err) => {
if (err) {
// it will return an error if the device is not connected
this._setSignalQuality(0);
} else {
let [quality] = result;
this._setSignalQuality(quality);
}
});
this._setSignalQuality(quality);
} catch (err) {
// it will return an error if the device is not connected
this._setSignalQuality(0);
}
}
});
@ -188,27 +188,28 @@ class ModemCdma extends ModemBase {
if (this.operator_name == null)
this._refreshServingSystem();
});
this._proxy.GetSignalQualityRemote((result, err) => {
if (err) {
// it will return an error if the device is not connected
this._setSignalQuality(0);
} else {
let [quality] = result;
this._setSignalQuality(quality);
}
});
this._getSignalQuality();
}
_refreshServingSystem() {
this._proxy.GetServingSystemRemote(([result], err) => {
if (err) {
// it will return an error if the device is not connected
this._setOperatorName(null);
} else {
let [bandClass_, band_, sid] = result;
this._setOperatorName(_findProviderForSid(sid));
}
});
async _getSignalQuality() {
try {
const [quality] = await this._proxy.GetSignalQualityAsync();
this._setSignalQuality(quality);
} catch (err) {
// it will return an error if the device is not connected
this._setSignalQuality(0);
}
}
async _refreshServingSystem() {
try {
const [bandClass_, band_, sid] =
await this._proxy.GetServingSystemAsync();
this._setOperatorName(_findProviderForSid(sid));
} catch (err) {
// it will return an error if the device is not connected
this._setOperatorName(null);
}
}
});