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

@ -43,87 +43,82 @@ var ExtensionsService = class extends ServiceImplementation {
this._proxy.UserExtensionsEnabled = enable; this._proxy.UserExtensionsEnabled = enable;
} }
ListExtensionsAsync(params, invocation) { async ListExtensionsAsync(params, invocation) {
this._proxy.ListExtensionsRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.ListExtensionsAsync(...params);
return;
invocation.return_value(new GLib.Variant('(a{sa{sv}})', res)); invocation.return_value(new GLib.Variant('(a{sa{sv}})', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
GetExtensionInfoAsync(params, invocation) { async GetExtensionInfoAsync(params, invocation) {
this._proxy.GetExtensionInfoRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.GetExtensionInfoAsync(...params);
return;
invocation.return_value(new GLib.Variant('(a{sv})', res)); invocation.return_value(new GLib.Variant('(a{sv})', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
GetExtensionErrorsAsync(params, invocation) { async GetExtensionErrorsAsync(params, invocation) {
this._proxy.GetExtensionErrorsRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.GetExtensionErrorsAsync(...params);
return;
invocation.return_value(new GLib.Variant('(as)', res)); invocation.return_value(new GLib.Variant('(as)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
InstallRemoteExtensionAsync(params, invocation) { async InstallRemoteExtensionAsync(params, invocation) {
this._proxy.InstallRemoteExtensionRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.InstallRemoteExtensionAsync(...params);
return;
invocation.return_value(new GLib.Variant('(s)', res)); invocation.return_value(new GLib.Variant('(s)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
UninstallExtensionAsync(params, invocation) { async UninstallExtensionAsync(params, invocation) {
this._proxy.UninstallExtensionRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.UninstallExtensionAsync(...params);
return;
invocation.return_value(new GLib.Variant('(b)', res)); invocation.return_value(new GLib.Variant('(b)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
EnableExtensionAsync(params, invocation) { async EnableExtensionAsync(params, invocation) {
this._proxy.EnableExtensionRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.EnableExtensionAsync(...params);
return;
invocation.return_value(new GLib.Variant('(b)', res)); invocation.return_value(new GLib.Variant('(b)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
DisableExtensionAsync(params, invocation) { async DisableExtensionAsync(params, invocation) {
this._proxy.DisableExtensionRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.DisableExtensionAsync(...params);
return;
invocation.return_value(new GLib.Variant('(b)', res)); invocation.return_value(new GLib.Variant('(b)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
LaunchExtensionPrefsAsync([uuid], invocation) { LaunchExtensionPrefsAsync([uuid], invocation) {
this.OpenExtensionPrefsAsync([uuid, '', {}], invocation); this.OpenExtensionPrefsAsync([uuid, '', {}], invocation);
} }
OpenExtensionPrefsAsync(params, invocation) { async OpenExtensionPrefsAsync(params, invocation) {
const [uuid, parentWindow, options] = params; const [uuid, parentWindow, options] = params;
this._proxy.GetExtensionInfoRemote(uuid, (res, error) => { try {
if (this._handleError(invocation, error)) const [serialized] = await this._proxy.GetExtensionInfoAsync(uuid);
return;
if (this._prefsDialog) { if (this._prefsDialog)
this._handleError(invocation, throw new Error('Already showing a prefs dialog');
new Error('Already showing a prefs dialog'));
return;
}
const [serialized] = res;
const extension = ExtensionUtils.deserializeExtension(serialized); const extension = ExtensionUtils.deserializeExtension(serialized);
this._prefsDialog = new ExtensionPrefsDialog(extension); this._prefsDialog = new ExtensionPrefsDialog(extension);
@ -150,15 +145,17 @@ var ExtensionsService = class extends ServiceImplementation {
this._prefsDialog.show(); this._prefsDialog.show();
invocation.return_value(null); invocation.return_value(null);
}); } catch (error) {
this._handleError(invocation, error);
}
} }
CheckForUpdatesAsync(params, invocation) { async CheckForUpdatesAsync(params, invocation) {
this._proxy.CheckForUpdatesRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) await this._proxy.CheckForUpdatesAsync(...params);
return;
invocation.return_value(null); invocation.return_value(null);
}); } catch (error) {
this._handleError(invocation, error);
}
} }
}; };

View File

@ -103,45 +103,44 @@ var NotificationDaemon = class extends ServiceImplementation {
'sender-pid': new GLib.Variant('u', pid), 'sender-pid': new GLib.Variant('u', pid),
}; };
this._proxy.NotifyRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const [id] = await this._proxy.NotifyAsync(...params);
return;
const [id] = res;
this._activeNotifications.set(id, sender); this._activeNotifications.set(id, sender);
invocation.return_value(new GLib.Variant('(u)', res)); invocation.return_value(new GLib.Variant('(u)', [id]));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
CloseNotificationAsync(params, invocation) { async CloseNotificationAsync(params, invocation) {
const [id] = params; const [id] = params;
if (!this._checkNotificationId(invocation, id)) if (!this._checkNotificationId(invocation, id))
return; return;
this._proxy.CloseNotificationRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) await this._proxy.CloseNotificationAsync(...params);
return;
invocation.return_value(null); invocation.return_value(null);
}); } catch (error) {
this._handleError(invocation, error);
}
} }
GetCapabilitiesAsync(params, invocation) { async GetCapabilitiesAsync(params, invocation) {
this._proxy.GetCapabilitiesRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.GetCapabilitiesAsync(...params);
return;
invocation.return_value(new GLib.Variant('(as)', res)); invocation.return_value(new GLib.Variant('(as)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
GetServerInformationAsync(params, invocation) { async GetServerInformationAsync(params, invocation) {
this._proxy.GetServerInformationRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.GetServerInformationAsync(...params);
return;
invocation.return_value(new GLib.Variant('(ssss)', res)); invocation.return_value(new GLib.Variant('(ssss)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
async _getSenderPid(sender) { async _getSenderPid(sender) {

View File

@ -32,39 +32,39 @@ var ScreenSaverService = class extends ServiceImplementation {
() => this._dbusImpl.emit_signal('WakeUpScreen', null)); () => this._dbusImpl.emit_signal('WakeUpScreen', null));
} }
LockAsync(params, invocation) { async LockAsync(params, invocation) {
this._proxy.LockRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) await this._proxy.LockAsync(...params);
return;
invocation.return_value(null); invocation.return_value(null);
}); } catch (error) {
this._handleError(invocation, error);
}
} }
GetActiveAsync(params, invocation) { async GetActiveAsync(params, invocation) {
this._proxy.GetActiveRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.GetActiveAsync(...params);
return;
invocation.return_value(new GLib.Variant('(b)', res)); invocation.return_value(new GLib.Variant('(b)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
SetActiveAsync(params, invocation) { async SetActiveAsync(params, invocation) {
this._proxy.SetActiveRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) await this._proxy.SetActiveAsync(...params);
return;
invocation.return_value(null); invocation.return_value(null);
}); } catch (error) {
this._handleError(invocation, error);
}
} }
GetActiveTimeAsync(params, invocation) { async GetActiveTimeAsync(params, invocation) {
this._proxy.GetActiveTimeRemote(...params, (res, error) => { try {
if (this._handleError(invocation, error)) const res = await this._proxy.GetActiveTimeAsync(...params);
return;
invocation.return_value(new GLib.Variant('(u)', res)); invocation.return_value(new GLib.Variant('(u)', res));
}); } catch (error) {
this._handleError(invocation, error);
}
} }
}; };

View File

@ -102,7 +102,7 @@ var Manager = class extends Signals.EventEmitter {
Service(Gio.DBus.system, Service(Gio.DBus.system,
'org.freedesktop.realmd', 'org.freedesktop.realmd',
'/org/freedesktop/realmd', '/org/freedesktop/realmd',
service => service.ReleaseRemote()); service => service.ReleaseAsync().catch(logError));
this._aggregateProvider.disconnectObject(this); this._aggregateProvider.disconnectObject(this);
this._realms = { }; this._realms = { };
this._updateLoginFormat(); this._updateLoginFormat();

View File

@ -376,7 +376,7 @@ var ShellUserVerifier = class extends Signals.EventEmitter {
this.emit('show-message', null, null, MessageType.NONE); this.emit('show-message', null, null, MessageType.NONE);
} }
_checkForFingerprintReader() { async _checkForFingerprintReader() {
this._fingerprintReaderType = FingerprintReaderType.NONE; this._fingerprintReaderType = FingerprintReaderType.NONE;
if (!this._settings.get_boolean(FINGERPRINT_AUTHENTICATION_KEY) || if (!this._settings.get_boolean(FINGERPRINT_AUTHENTICATION_KEY) ||
@ -385,10 +385,9 @@ var ShellUserVerifier = class extends Signals.EventEmitter {
return; return;
} }
this._fprintManager.GetDefaultDeviceRemote(Gio.DBusCallFlags.NONE, this._cancellable, try {
(params, error) => { const [device] = await this._fprintManager.GetDefaultDeviceAsync(
if (!error && params) { Gio.DBusCallFlags.NONE, this._cancellable);
const [device] = params;
const fprintDeviceProxy = new FprintDeviceProxy(Gio.DBus.system, const fprintDeviceProxy = new FprintDeviceProxy(Gio.DBus.system,
'net.reactivated.Fprint', 'net.reactivated.Fprint',
device); device);
@ -398,8 +397,7 @@ var ShellUserVerifier = class extends Signals.EventEmitter {
? FingerprintReaderType.SWIPE ? FingerprintReaderType.SWIPE
: FingerprintReaderType.PRESS; : FingerprintReaderType.PRESS;
this._updateDefaultService(); this._updateDefaultService();
} } catch (e) {}
});
} }
_onCredentialManagerAuthenticated(credentialManager, _token) { _onCredentialManagerAuthenticated(credentialManager, _token) {

View File

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

View File

@ -329,11 +329,14 @@ const SystemActions = GObject.registerClass({
this.notify('can-lock-screen'); this.notify('can-lock-screen');
} }
_updateHaveShutdown() { async _updateHaveShutdown() {
this._session.CanShutdownRemote((result, error) => { try {
this._canHavePowerOff = error ? false : result[0]; const [canShutdown] = await this._session.CanShutdownAsync();
this._canHavePowerOff = canShutdown;
} catch (e) {
this._canHavePowerOff = false;
}
this._updatePowerOff(); this._updatePowerOff();
});
} }
_updatePowerOff() { _updatePowerOff() {
@ -431,21 +434,21 @@ const SystemActions = GObject.registerClass({
throw new Error('The logout action is not available!'); throw new Error('The logout action is not available!');
Main.overview.hide(); Main.overview.hide();
this._session.LogoutRemote(0); this._session.LogoutAsync(0).catch(logError);
} }
activatePowerOff() { activatePowerOff() {
if (!this._actions.get(POWER_OFF_ACTION_ID).available) if (!this._actions.get(POWER_OFF_ACTION_ID).available)
throw new Error('The power-off action is not available!'); throw new Error('The power-off action is not available!');
this._session.ShutdownRemote(0); this._session.ShutdownAsync(0).catch(logError);
} }
activateRestart() { activateRestart() {
if (!this._actions.get(RESTART_ACTION_ID).available) if (!this._actions.get(RESTART_ACTION_ID).available)
throw new Error('The restart action is not available!'); throw new Error('The restart action is not available!');
this._session.RebootRemote(); this._session.RebootAsync().catch(logError);
} }
activateSuspend() { activateSuspend() {

View File

@ -39,7 +39,7 @@ var WeatherClient = class extends Signals.EventEmitter {
this._needsAuth = true; this._needsAuth = true;
this._weatherAuthorized = false; this._weatherAuthorized = false;
this._permStore = new PermissionStore.PermissionStore((proxy, error) => { this._permStore = new PermissionStore.PermissionStore(async (proxy, error) => {
if (error) { if (error) {
log(`Failed to connect to permissionStore: ${error.message}`); log(`Failed to connect to permissionStore: ${error.message}`);
return; return;
@ -53,15 +53,16 @@ var WeatherClient = class extends Signals.EventEmitter {
return; return;
} }
this._permStore.LookupRemote('gnome', 'geolocation', (res, err) => { let [perms, data] = [{}, null];
if (err) try {
[perms, data] = await this._permStore.LookupAsync('gnome', 'geolocation');
} catch (err) {
log(`Error looking up permission: ${err.message}`); log(`Error looking up permission: ${err.message}`);
}
let [perms, data] = err ? [{}, null] : res; const params = ['gnome', 'geolocation', false, data, perms];
let params = ['gnome', 'geolocation', false, data, perms];
this._onPermStoreChanged(this._permStore, '', params); this._onPermStoreChanged(this._permStore, '', params);
}); });
});
this._permStore.connectSignal('Changed', this._permStore.connectSignal('Changed',
this._onPermStoreChanged.bind(this)); this._onPermStoreChanged.bind(this));

View File

@ -337,11 +337,11 @@ class DBusEventSource extends EventSourceBase {
this._events.clear(); this._events.clear();
this.emit('changed'); this.emit('changed');
} }
this._dbusProxy.SetTimeRangeRemote( this._dbusProxy.SetTimeRangeAsync(
this._curRequestBegin.getTime() / 1000, this._curRequestBegin.getTime() / 1000,
this._curRequestEnd.getTime() / 1000, this._curRequestEnd.getTime() / 1000,
forceReload, forceReload,
Gio.DBusCallFlags.NONE); Gio.DBusCallFlags.NONE).catch(logError);
} }
} }

View File

@ -51,12 +51,12 @@ var AutomountManager = class {
} }
} }
_InhibitorsChanged(_object, _senderName, [_inhibitor]) { async _InhibitorsChanged(_object, _senderName, [_inhibitor]) {
this._session.IsInhibitedRemote(GNOME_SESSION_AUTOMOUNT_INHIBIT, try {
(result, error) => { const [inhibited] =
if (!error) await this._session.IsInhibitedAsync(GNOME_SESSION_AUTOMOUNT_INHIBIT);
this._inhibited = result[0]; this._inhibited = inhibited;
}); } catch (e) {}
} }
_startupMountAll() { _startupMountAll() {

View File

@ -504,89 +504,73 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
this._confirm('ConfirmedReboot'); this._confirm('ConfirmedReboot');
} }
_confirm(signal) { async _confirm(signal) {
let callback = () => { if (this._checkBox.visible) {
// Trigger the offline update as requested
if (this._checkBox.checked) {
switch (signal) {
case 'ConfirmedReboot':
await this._triggerOfflineUpdateReboot();
break;
case 'ConfirmedShutdown':
// To actually trigger the offline update, we need to
// reboot to do the upgrade. When the upgrade is complete,
// the computer will shut down automatically.
signal = 'ConfirmedReboot';
await this._triggerOfflineUpdateShutdown();
break;
default:
break;
}
} else {
await this._triggerOfflineUpdateCancel();
}
}
this._fadeOutDialog(); this._fadeOutDialog();
this._stopTimer(); this._stopTimer();
this._stopAltCapture(); this._stopAltCapture();
this._dbusImpl.emit_signal(signal, null); this._dbusImpl.emit_signal(signal, null);
};
// Offline update not available; just emit the signal
if (!this._checkBox.visible) {
callback();
return;
}
// Trigger the offline update as requested
if (this._checkBox.checked) {
switch (signal) {
case "ConfirmedReboot":
this._triggerOfflineUpdateReboot(callback);
break;
case "ConfirmedShutdown":
// To actually trigger the offline update, we need to
// reboot to do the upgrade. When the upgrade is complete,
// the computer will shut down automatically.
signal = "ConfirmedReboot";
this._triggerOfflineUpdateShutdown(callback);
break;
default:
callback();
break;
}
} else {
this._triggerOfflineUpdateCancel(callback);
}
} }
_onOpened() { _onOpened() {
this._sync(); this._sync();
} }
_triggerOfflineUpdateReboot(callback) { async _triggerOfflineUpdateReboot() {
// Handle this gracefully if PackageKit is not available. // Handle this gracefully if PackageKit is not available.
if (!this._pkOfflineProxy) { if (!this._pkOfflineProxy)
callback();
return; return;
}
this._pkOfflineProxy.TriggerRemote('reboot', (result, error) => { try {
if (error) await this._pkOfflineProxy.TriggerAsync('reboot');
} catch (error) {
log(error.message); log(error.message);
}
callback();
});
} }
_triggerOfflineUpdateShutdown(callback) { async _triggerOfflineUpdateShutdown() {
// Handle this gracefully if PackageKit is not available. // Handle this gracefully if PackageKit is not available.
if (!this._pkOfflineProxy) { if (!this._pkOfflineProxy)
callback();
return; return;
}
this._pkOfflineProxy.TriggerRemote('power-off', (result, error) => { try {
if (error) await this._pkOfflineProxy.TriggerAsync('power-off');
} catch (error) {
log(error.message); log(error.message);
}
callback();
});
} }
_triggerOfflineUpdateCancel(callback) { async _triggerOfflineUpdateCancel() {
// Handle this gracefully if PackageKit is not available. // Handle this gracefully if PackageKit is not available.
if (!this._pkOfflineProxy) { if (!this._pkOfflineProxy)
callback();
return; return;
}
this._pkOfflineProxy.CancelRemote((result, error) => { try {
if (error) await this._pkOfflineProxy.CancelAsync();
} catch (error) {
log(error.message); log(error.message);
}
callback();
});
} }
_startTimer() { _startTimer() {

View File

@ -53,7 +53,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
return this._app && !this._app.is_window_backed(); return this._app && !this._app.is_window_backed();
} }
_saveToPermissionStore(grant) { async _saveToPermissionStore(grant) {
if (!this._shouldUsePermStore() || this._permStore == null) if (!this._shouldUsePermStore() || this._permStore == null)
return; return;
@ -61,15 +61,15 @@ var InhibitShortcutsDialog = GObject.registerClass({
permissions[this._app.get_id()] = [grant]; permissions[this._app.get_id()] = [grant];
let data = GLib.Variant.new('av', {}); let data = GLib.Variant.new('av', {});
this._permStore.SetRemote(APP_PERMISSIONS_TABLE, try {
await this._permStore.SetAsync(APP_PERMISSIONS_TABLE,
true, true,
APP_PERMISSIONS_ID, APP_PERMISSIONS_ID,
permissions, permissions,
data, data);
(result, error) => { } catch (error) {
if (error != null)
log(error.message); log(error.message);
}); }
} }
_buildLayout() { _buildLayout() {
@ -134,30 +134,27 @@ var InhibitShortcutsDialog = GObject.registerClass({
/* Check with the permission store */ /* Check with the permission store */
let appId = this._app.get_id(); let appId = this._app.get_id();
this._permStore = new PermissionStore.PermissionStore((proxy, error) => { this._permStore = new PermissionStore.PermissionStore(async (proxy, error) => {
if (error) { if (error) {
log(error.message); log(error.message);
this._dialog.open(); this._dialog.open();
return; return;
} }
this._permStore.LookupRemote(APP_PERMISSIONS_TABLE, try {
APP_PERMISSIONS_ID, const [permissions] = await this._permStore.LookupAsync(
(res, err) => { APP_PERMISSIONS_TABLE, APP_PERMISSIONS_ID);
if (err) {
this._dialog.open();
log(err.message);
return;
}
let [permissions] = res;
if (permissions[appId] === undefined) // Not found if (permissions[appId] === undefined) // Not found
this._dialog.open(); this._dialog.open();
else if (permissions[appId] == GRANTED) else if (permissions[appId] === GRANTED)
this._emitResponse(DialogResponse.ALLOW); this._emitResponse(DialogResponse.ALLOW);
else else
this._emitResponse(DialogResponse.DENY); this._emitResponse(DialogResponse.DENY);
}); } catch (err) {
this._dialog.open();
log(err.message);
}
}); });
} }

View File

@ -121,7 +121,7 @@ var MprisPlayer = class MprisPlayer extends Signals.EventEmitter {
} }
playPause() { playPause() {
this._playerProxy.PlayPauseRemote(); this._playerProxy.PlayPauseAsync().catch(logError);
} }
get canGoNext() { get canGoNext() {
@ -129,7 +129,7 @@ var MprisPlayer = class MprisPlayer extends Signals.EventEmitter {
} }
next() { next() {
this._playerProxy.NextRemote(); this._playerProxy.NextAsync().catch(logError);
} }
get canGoPrevious() { get canGoPrevious() {
@ -137,7 +137,7 @@ var MprisPlayer = class MprisPlayer extends Signals.EventEmitter {
} }
previous() { previous() {
this._playerProxy.PreviousRemote(); this._playerProxy.PreviousAsync().catch(logError);
} }
raise() { raise() {
@ -152,7 +152,7 @@ var MprisPlayer = class MprisPlayer extends Signals.EventEmitter {
if (app) if (app)
app.activate(); app.activate();
else if (this._mprisProxy.CanRaise) else if (this._mprisProxy.CanRaise)
this._mprisProxy.RaiseRemote(); this._mprisProxy.RaiseAsync().catch(logError);
} }
_close() { _close() {
@ -275,15 +275,14 @@ class MediaSection extends MessageList.MessageListSection {
this._players.set(busName, player); this._players.set(busName, player);
} }
_onProxyReady() { async _onProxyReady() {
this._proxy.ListNamesRemote(([names]) => { const [names] = await this._proxy.ListNamesAsync();
names.forEach(name => { names.forEach(name => {
if (!name.startsWith(MPRIS_PLAYER_PREFIX)) if (!name.startsWith(MPRIS_PLAYER_PREFIX))
return; return;
this._addPlayer(name); this._addPlayer(name);
}); });
});
this._proxy.connectSignal('NameOwnerChanged', this._proxy.connectSignal('NameOwnerChanged',
this._onNameOwnerChanged.bind(this)); this._onNameOwnerChanged.bind(this));
} }

View File

@ -575,32 +575,41 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
return new MessageTray.NotificationApplicationPolicy(this._appId); return new MessageTray.NotificationApplicationPolicy(this._appId);
} }
_createApp(callback) { _createApp() {
return new FdoApplicationProxy(Gio.DBus.session, this._appId, this._objectPath, callback); return new Promise((resolve, reject) => {
new FdoApplicationProxy(Gio.DBus.session,
this._appId, this._objectPath, (proxy, err) => {
if (err)
reject(err);
else
resolve(proxy);
});
});
} }
_createNotification(params) { _createNotification(params) {
return new GtkNotificationDaemonNotification(this, params); return new GtkNotificationDaemonNotification(this, params);
} }
activateAction(actionId, target) { async activateAction(actionId, target) {
this._createApp((app, error) => { try {
if (error == null) const app = await this._createApp();
app.ActivateActionRemote(actionId, target ? [target] : [], getPlatformData()); const params = target ? [target] : [];
else app.ActivateActionAsync(actionId, params, getPlatformData());
} catch (error) {
logError(error, 'Failed to activate application proxy'); logError(error, 'Failed to activate application proxy');
}); }
Main.overview.hide(); Main.overview.hide();
Main.panel.closeCalendar(); Main.panel.closeCalendar();
} }
open() { async open() {
this._createApp((app, error) => { try {
if (error == null) const app = await this._createApp();
app.ActivateRemote(getPlatformData()); app.ActivateAsync(getPlatformData());
else } catch (error) {
logError(error, 'Failed to open application proxy'); logError(error, 'Failed to open application proxy');
}); }
Main.overview.hide(); Main.overview.hide();
Main.panel.closeCalendar(); Main.panel.closeCalendar();
} }

View File

@ -302,7 +302,7 @@ var RemoteSearchProvider = class {
} }
activateResult(id) { activateResult(id) {
this.proxy.ActivateResultRemote(id); this.proxy.ActivateResultAsync(id).catch(logError);
} }
launchSearch(_terms) { launchSearch(_terms) {
@ -321,10 +321,12 @@ var RemoteSearchProvider2 = class extends RemoteSearchProvider {
} }
activateResult(id, terms) { activateResult(id, terms) {
this.proxy.ActivateResultRemote(id, terms, global.get_current_time()); this.proxy.ActivateResultAsync(
id, terms, global.get_current_time()).catch(logError);
} }
launchSearch(terms) { launchSearch(terms) {
this.proxy.LaunchSearchRemote(terms, global.get_current_time()); this.proxy.LaunchSearchAsync(
terms, global.get_current_time()).catch(logError);
} }
}; };

View File

@ -173,7 +173,7 @@ var ScreenShield = class extends Signals.EventEmitter {
this.emit('locked-changed'); this.emit('locked-changed');
if (this._loginSession) if (this._loginSession)
this._loginSession.SetLockedHintRemote(locked); this._loginSession.SetLockedHintAsync(locked).catch(logError);
} }
_activateDialog() { _activateDialog() {

View File

@ -1824,15 +1824,16 @@ var ScreenshotUI = GObject.registerClass({
this.close(true); this.close(true);
// This is a bit awkward because creating a proxy synchronously hangs Shell. // This is a bit awkward because creating a proxy synchronously hangs Shell.
const doStartScreencast = () => { const doStartScreencast = async () => {
let method = let method =
this._screencastProxy.ScreencastRemote.bind(this._screencastProxy); this._screencastProxy.ScreencastAsync.bind(this._screencastProxy);
if (w !== -1) { if (w !== -1) {
method = this._screencastProxy.ScreencastAreaRemote.bind( method = this._screencastProxy.ScreencastAreaAsync.bind(
this._screencastProxy, x, y, w, h); this._screencastProxy, x, y, w, h);
} }
method( try {
const [success, path] = await method(
GLib.build_filenamev([ GLib.build_filenamev([
/* Translators: this is the folder where recorded /* Translators: this is the folder where recorded
screencasts are stored. */ screencasts are stored. */
@ -1843,23 +1844,18 @@ var ScreenshotUI = GObject.registerClass({
/* xgettext:no-c-format */ /* xgettext:no-c-format */
_('Screencast from %d %t.webm'), _('Screencast from %d %t.webm'),
]), ]),
{ 'draw-cursor': new GLib.Variant('b', drawCursor) }, {'draw-cursor': new GLib.Variant('b', drawCursor)});
([success, path], error) => { if (!success)
if (error !== null) { throw new Error();
this._setScreencastInProgress(false);
log(`Error starting screencast: ${error.message}`);
return;
}
if (!success) {
this._setScreencastInProgress(false);
log('Error starting screencast');
return;
}
this._screencastPath = path; this._screencastPath = path;
} catch (error) {
this._setScreencastInProgress(false);
const {message} = error;
if (message)
log(`Error starting screencast: ${message}`);
else
log('Error starting screencast');
} }
);
}; };
// Set this before calling the method as the screen recording indicator // Set this before calling the method as the screen recording indicator
@ -1886,7 +1882,7 @@ var ScreenshotUI = GObject.registerClass({
} }
} }
stopScreencast() { async stopScreencast() {
if (!this._screencastInProgress) if (!this._screencastInProgress)
return; return;
@ -1894,13 +1890,15 @@ var ScreenshotUI = GObject.registerClass({
// will check it before the success callback fires. // will check it before the success callback fires.
this._setScreencastInProgress(false); this._setScreencastInProgress(false);
this._screencastProxy.StopScreencastRemote((success, error) => { try {
if (error !== null) { const [success] = await this._screencastProxy.StopScreencastAsync();
log(`Error stopping screencast: ${error.message}`); if (!success)
return; throw new Error();
} } catch (error) {
const {message} = error;
if (!success) { if (message)
log(`Error stopping screencast: ${message}`);
else
log('Error stopping screencast'); log('Error stopping screencast');
return; return;
} }
@ -1945,7 +1943,6 @@ var ScreenshotUI = GObject.registerClass({
Main.messageTray.add(source); Main.messageTray.add(source);
source.showNotification(notification); source.showNotification(notification);
});
} }
get screencast_in_progress() { get screencast_in_progress() {

View File

@ -82,19 +82,6 @@ function _spawnPerfHelper() {
Util.trySpawnCommandLine(command); Util.trySpawnCommandLine(command);
} }
function _callRemote(obj, method, ...args) {
return new Promise((resolve, reject) => {
args.push((result, excp) => {
if (excp)
reject(excp);
else
resolve();
});
method.apply(obj, args);
});
}
/** /**
* createTestWindow: * createTestWindow:
* @param {Object} params: options for window creation. * @param {Object} params: options for window creation.
@ -121,9 +108,9 @@ function createTestWindow(params) {
}); });
let perfHelper = _getPerfHelper(); let perfHelper = _getPerfHelper();
return _callRemote(perfHelper, perfHelper.CreateWindowRemote, perfHelper.CreateWindowAsync(
params.width, params.height, params.width, params.height,
params.alpha, params.maximized, params.redraws); params.alpha, params.maximized, params.redraws).catch(logError);
} }
/** /**
@ -135,7 +122,7 @@ function createTestWindow(params) {
*/ */
function waitTestWindows() { function waitTestWindows() {
let perfHelper = _getPerfHelper(); let perfHelper = _getPerfHelper();
return _callRemote(perfHelper, perfHelper.WaitWindowsRemote); perfHelper.WaitWindowsAsync().catch(logError);
} }
/** /**
@ -150,7 +137,7 @@ function waitTestWindows() {
*/ */
function destroyTestWindows() { function destroyTestWindows() {
let perfHelper = _getPerfHelper(); let perfHelper = _getPerfHelper();
return _callRemote(perfHelper, perfHelper.DestroyWindowsRemote); perfHelper.DestroyWindowsAsync().catch(logError);
} }
/** /**

View File

@ -137,7 +137,7 @@ var GeoclueAgent = GObject.registerClass({
return true; return true;
} }
_onManagerProxyReady(proxy, error) { async _onManagerProxyReady(proxy, error) {
if (error != null) { if (error != null) {
log(error.message); log(error.message);
this._connecting = false; this._connecting = false;
@ -150,15 +150,13 @@ var GeoclueAgent = GObject.registerClass({
this.notify('in-use'); this.notify('in-use');
this._managerProxy.AddAgentRemote('gnome-shell', this._onAgentRegistered.bind(this)); try {
} await this._managerProxy.AddAgentAsync('gnome-shell');
_onAgentRegistered(result, error) {
this._connecting = false; this._connecting = false;
this._notifyMaxAccuracyLevel(); this._notifyMaxAccuracyLevel();
} catch (e) {
if (error != null) log(e.message);
log(error.message); }
} }
_onGeoclueVanished() { _onGeoclueVanished() {
@ -298,7 +296,7 @@ var AppAuthorizer = class {
return this._accuracyLevel; return this._accuracyLevel;
} }
_saveToPermissionStore() { async _saveToPermissionStore() {
if (this._permStoreProxy == null) if (this._permStoreProxy == null)
return; return;
@ -308,15 +306,16 @@ var AppAuthorizer = class {
let data = GLib.Variant.new('av', {}); let data = GLib.Variant.new('av', {});
this._permStoreProxy.SetRemote(APP_PERMISSIONS_TABLE, try {
await this._permStoreProxy.SetAsync(
APP_PERMISSIONS_TABLE,
true, true,
APP_PERMISSIONS_ID, APP_PERMISSIONS_ID,
this._permissions, this._permissions,
data, data);
(result, error) => { } catch (error) {
if (error != null)
log(error.message); log(error.message);
}); }
} }
}; };

View File

@ -50,7 +50,7 @@ var PortalHelperResult = {
}; };
const PortalHelperIface = loadInterfaceXML('org.gnome.Shell.PortalHelper'); const PortalHelperIface = loadInterfaceXML('org.gnome.Shell.PortalHelper');
const PortalHelperProxy = Gio.DBusProxy.makeProxyWrapper(PortalHelperIface); const PortalHelperInfo = Gio.DBusInterfaceInfo.new_for_xml(PortalHelperIface);
function signalToIcon(value) { function signalToIcon(value) {
if (value < 20) if (value < 20)
@ -2090,7 +2090,7 @@ class Indicator extends PanelMenu.SystemIndicator {
_flushConnectivityQueue() { _flushConnectivityQueue() {
if (this._portalHelperProxy) { if (this._portalHelperProxy) {
for (let item of this._connectivityQueue) for (let item of this._connectivityQueue)
this._portalHelperProxy.CloseRemote(item); this._portalHelperProxy.CloseAsync(item).catch(logError);
} }
this._connectivityQueue = []; this._connectivityQueue = [];
@ -2101,7 +2101,7 @@ class Indicator extends PanelMenu.SystemIndicator {
if (index >= 0) { if (index >= 0) {
if (this._portalHelperProxy) if (this._portalHelperProxy)
this._portalHelperProxy.CloseRemote(path); this._portalHelperProxy.CloseAsync(path).catch(logError);
this._connectivityQueue.splice(index, 1); this._connectivityQueue.splice(index, 1);
} }
@ -2128,7 +2128,7 @@ class Indicator extends PanelMenu.SystemIndicator {
} }
} }
_syncConnectivity() { async _syncConnectivity() {
if (this._mainConnection == null || if (this._mainConnection == null ||
this._mainConnection.state != NM.ActiveConnectionState.ACTIVATED) { this._mainConnection.state != NM.ActiveConnectionState.ACTIVATED) {
this._flushConnectivityQueue(); this._flushConnectivityQueue();
@ -2153,24 +2153,26 @@ class Indicator extends PanelMenu.SystemIndicator {
} }
let timestamp = global.get_current_time(); let timestamp = global.get_current_time();
if (this._portalHelperProxy) { if (!this._portalHelperProxy) {
this._portalHelperProxy.AuthenticateRemote(path, '', timestamp); this._portalHelperProxy = new Gio.DBusProxy({
} else { g_connection: Gio.DBus.session,
new PortalHelperProxy(Gio.DBus.session, g_name: 'org.gnome.Shell.PortalHelper',
'org.gnome.Shell.PortalHelper', g_object_path: '/org/gnome/Shell/PortalHelper',
'/org/gnome/Shell/PortalHelper', g_interface_name: PortalHelperInfo.name,
(proxy, error) => { g_interface_info: PortalHelperInfo,
if (error) {
log(`Error launching the portal helper: ${error}`);
return;
}
this._portalHelperProxy = proxy;
proxy.connectSignal('Done', this._portalHelperDone.bind(this));
proxy.AuthenticateRemote(path, '', timestamp);
}); });
this._portalHelperProxy.connectSignal('Done',
() => this._portalHelperDone().catch(logError));
try {
await this._portalHelperProxy.init_async(
GLib.PRIORITY_DEFAULT, null);
} catch (e) {
console.error(`Error launching the portal helper: ${e.message}`);
} }
}
this._portalHelperProxy?.AuthenticateAsync(path, '', timestamp).catch(logError);
this._connectivityQueue.push(path); this._connectivityQueue.push(path);
} }

View File

@ -109,20 +109,15 @@ var Client = class extends Signals.EventEmitter {
this._proxy = null; this._proxy = null;
} }
enrollDevice(id, policy, callback) { async enrollDevice(id, policy) {
this._proxy.EnrollDeviceRemote(id, policy, AuthCtrl.NONE, (res, error) => { try {
if (error) { const [path] = await this._proxy.EnrollDeviceAsync(id, policy, AuthCtrl.NONE);
const device = new BoltDeviceProxy(Gio.DBus.system, BOLT_DBUS_NAME, path);
return device;
} catch (error) {
Gio.DBusError.strip_remote_error(error); Gio.DBusError.strip_remote_error(error);
callback(null, error); throw error;
return;
} }
let [path] = res;
let device = new BoltDeviceProxy(Gio.DBus.system,
BOLT_DBUS_NAME,
path);
callback(device, null);
});
} }
get authMode() { get authMode() {
@ -191,9 +186,15 @@ var AuthRobot = class extends Signals.EventEmitter {
this._enrollDevicesIdle.bind(this)); this._enrollDevicesIdle.bind(this));
} }
_onEnrollDone(device, error) { async _enrollDevicesIdle() {
if (error) let devices = this._devicesToEnroll;
this.emit('enroll-failed', device, error);
let dev = devices.shift();
if (dev === undefined)
return GLib.SOURCE_REMOVE;
try {
await this._client.enrollDevice(dev.Uid, Policy.DEFAULT);
/* TODO: scan the list of devices to be authorized for children /* TODO: scan the list of devices to be authorized for children
* of this device and remove them (and their children and * of this device and remove them (and their children and
@ -205,18 +206,9 @@ var AuthRobot = class extends Signals.EventEmitter {
GLib.idle_add(GLib.PRIORITY_DEFAULT, GLib.idle_add(GLib.PRIORITY_DEFAULT,
this._enrollDevicesIdle.bind(this)); this._enrollDevicesIdle.bind(this));
} }
} catch (error) {
this.emit('enroll-failed', null, error);
} }
_enrollDevicesIdle() {
let devices = this._devicesToEnroll;
let dev = devices.shift();
if (dev === undefined)
return GLib.SOURCE_REMOVE;
this._client.enrollDevice(dev.Uid,
Policy.DEFAULT,
this._onEnrollDone.bind(this));
return GLib.SOURCE_REMOVE; return GLib.SOURCE_REMOVE;
} }
}; };

View File

@ -894,8 +894,8 @@ var WindowManager = class {
labels.push(str ?? ''); labels.push(str ?? '');
} }
if (this._gsdWacomProxy) this._gsdWacomProxy?.SetOLEDLabelsAsync(
this._gsdWacomProxy.SetOLEDLabelsRemote(pad.get_device_node(), labels); pad.get_device_node(), labels).catch(logError);
}); });
global.display.connect('init-xserver', (display, task) => { global.display.connect('init-xserver', (display, task) => {

View File

@ -51,7 +51,7 @@ class Application extends Adw.Application {
} }
vfunc_activate() { vfunc_activate() {
this._shellProxy.CheckForUpdatesRemote(); this._shellProxy.CheckForUpdatesAsync().catch(logError);
this._window.present(); this._window.present();
} }
@ -176,7 +176,7 @@ var ExtensionsWindow = GObject.registerClass({
dialog.connect('response', (dlg, response) => { dialog.connect('response', (dlg, response) => {
if (response === Gtk.ResponseType.ACCEPT) if (response === Gtk.ResponseType.ACCEPT)
this._shellProxy.UninstallExtensionRemote(uuid); this._shellProxy.UninstallExtensionAsync(uuid).catch(logError);
dialog.destroy(); dialog.destroy();
}); });
dialog.present(); dialog.present();
@ -191,9 +191,9 @@ var ExtensionsWindow = GObject.registerClass({
} }
} }
this._shellProxy.OpenExtensionPrefsRemote(uuid, this._shellProxy.OpenExtensionPrefsAsync(uuid,
this._exportedHandle, this._exportedHandle,
{ modal: new GLib.Variant('b', true) }); {modal: new GLib.Variant('b', true)}).catch(logError);
} }
_showAbout() { _showAbout() {
@ -281,24 +281,23 @@ var ExtensionsWindow = GObject.registerClass({
this._syncListVisibility(); this._syncListVisibility();
} }
_scanExtensions() { async _scanExtensions() {
this._shellProxy.ListExtensionsRemote(([extensionsMap], e) => { try {
if (e) { const [extensionsMap] = await this._shellProxy.ListExtensionsAsync();
if (e instanceof Gio.DBusError) {
log(`Failed to connect to shell proxy: ${e}`);
this._mainStack.visible_child_name = 'noshell';
} else {
throw e;
}
return;
}
for (let uuid in extensionsMap) { for (let uuid in extensionsMap) {
let extension = ExtensionUtils.deserializeExtension(extensionsMap[uuid]); let extension = ExtensionUtils.deserializeExtension(extensionsMap[uuid]);
this._addExtensionRow(extension); this._addExtensionRow(extension);
} }
this._extensionsLoaded(); this._extensionsLoaded();
}); } catch (e) {
if (e instanceof Gio.DBusError) {
log(`Failed to connect to shell proxy: ${e}`);
this._mainStack.visible_child_name = 'noshell';
} else {
throw e;
}
}
} }
_addExtensionRow(extension) { _addExtensionRow(extension) {
@ -407,9 +406,9 @@ var ExtensionRow = GObject.registerClass({
action.connect('activate', toggleState); action.connect('activate', toggleState);
action.connect('change-state', (a, state) => { action.connect('change-state', (a, state) => {
if (state.get_boolean()) if (state.get_boolean())
this._app.shellProxy.EnableExtensionRemote(this.uuid); this._app.shellProxy.EnableExtensionAsync(this.uuid).catch(logError);
else else
this._app.shellProxy.DisableExtensionRemote(this.uuid); this._app.shellProxy.DisableExtensionAsync(this.uuid).catch(logError);
}); });
this._actionGroup.add_action(action); this._actionGroup.add_action(action);