[gnome-shell] js: Simplify promisify() calls



commit 5442266f2882d5ddbf1d714103ee0c13d500e399
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Feb 11 00:09:54 2022 +0100

    js: Simplify promisify() calls
    
    If the finish function isn't specified, promisify will now try
    to use the async name without '_async'/'_begin' suffix (if any)
    and '_finish' appended.
    
    Everything except IBus uses a variation of that pattern, so there's
    quite a bit of boilerplate we get to remove…
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2174>

 js/dbusServices/notifications/notificationDaemon.js |  2 +-
 js/gdm/util.js                                      | 11 ++++-------
 js/misc/parentalControlsManager.js                  |  2 +-
 js/misc/weather.js                                  |  2 +-
 js/ui/background.js                                 |  2 +-
 js/ui/components/networkAgent.js                    |  5 ++---
 js/ui/components/telepathyClient.js                 | 11 ++++-------
 js/ui/environment.js                                | 18 ++++++++----------
 js/ui/extensionDownloader.js                        | 12 ++++--------
 js/ui/main.js                                       |  4 ++--
 js/ui/screenshot.js                                 | 17 ++++++-----------
 js/ui/status/network.js                             |  7 +++----
 js/ui/windowManager.js                              |  6 ++----
 subprojects/extensions-app/js/main.js               |  4 ++--
 14 files changed, 41 insertions(+), 62 deletions(-)
---
diff --git a/js/dbusServices/notifications/notificationDaemon.js 
b/js/dbusServices/notifications/notificationDaemon.js
index 139075256e..d0c97860cb 100644
--- a/js/dbusServices/notifications/notificationDaemon.js
+++ b/js/dbusServices/notifications/notificationDaemon.js
@@ -9,7 +9,7 @@ const { ServiceImplementation } = imports.dbusService;
 const NotificationsIface = loadInterfaceXML('org.freedesktop.Notifications');
 const NotificationsProxy = Gio.DBusProxy.makeProxyWrapper(NotificationsIface);
 
-Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
+Gio._promisify(Gio.DBusConnection.prototype, 'call');
 
 var NotificationDaemon = class extends ServiceImplementation {
     constructor() {
diff --git a/js/gdm/util.js b/js/gdm/util.js
index b5f31a2ffc..d310099a61 100644
--- a/js/gdm/util.js
+++ b/js/gdm/util.js
@@ -18,14 +18,11 @@ const FprintManagerProxy = Gio.DBusProxy.makeProxyWrapper(FprintManagerIface);
 const FprintDeviceIface = loadInterfaceXML('net.reactivated.Fprint.Device');
 const FprintDeviceProxy = Gio.DBusProxy.makeProxyWrapper(FprintDeviceIface);
 
-Gio._promisify(Gdm.Client.prototype,
-    'open_reauthentication_channel', 'open_reauthentication_channel_finish');
-Gio._promisify(Gdm.Client.prototype,
-    'get_user_verifier', 'get_user_verifier_finish');
+Gio._promisify(Gdm.Client.prototype, 'open_reauthentication_channel');
+Gio._promisify(Gdm.Client.prototype, 'get_user_verifier');
 Gio._promisify(Gdm.UserVerifierProxy.prototype,
-    'call_begin_verification_for_user', 'call_begin_verification_for_user_finish');
-Gio._promisify(Gdm.UserVerifierProxy.prototype,
-    'call_begin_verification', 'call_begin_verification_finish');
+    'call_begin_verification_for_user');
+Gio._promisify(Gdm.UserVerifierProxy.prototype, 'call_begin_verification');
 
 var PASSWORD_SERVICE_NAME = 'gdm-password';
 var FINGERPRINT_SERVICE_NAME = 'gdm-fingerprint';
diff --git a/js/misc/parentalControlsManager.js b/js/misc/parentalControlsManager.js
index fc1e7ced6f..092721133a 100644
--- a/js/misc/parentalControlsManager.js
+++ b/js/misc/parentalControlsManager.js
@@ -32,7 +32,7 @@ const HAVE_MALCONTENT = imports.package.checkSymbol(
 var Malcontent = null;
 if (HAVE_MALCONTENT) {
     Malcontent = imports.gi.Malcontent;
-    Gio._promisify(Malcontent.Manager.prototype, 'get_app_filter_async', 'get_app_filter_finish');
+    Gio._promisify(Malcontent.Manager.prototype, 'get_app_filter_async');
 }
 
 let _singleton = null;
diff --git a/js/misc/weather.js b/js/misc/weather.js
index 2c7480a7d0..1cd4e38ee3 100644
--- a/js/misc/weather.js
+++ b/js/misc/weather.js
@@ -7,7 +7,7 @@ const PermissionStore = imports.misc.permissionStore;
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
-Gio._promisify(Geoclue.Simple, 'new', 'new_finish');
+Gio._promisify(Geoclue.Simple, 'new');
 
 const WeatherIntegrationIface = loadInterfaceXML('org.gnome.Shell.WeatherIntegration');
 
diff --git a/js/ui/background.js b/js/ui/background.js
index 7a22e803bb..a3389c7926 100644
--- a/js/ui/background.js
+++ b/js/ui/background.js
@@ -101,7 +101,7 @@ const LoginManager = imports.misc.loginManager;
 const Main = imports.ui.main;
 const Params = imports.misc.params;
 
-Gio._promisify(Gio.File.prototype, 'query_info_async', 'query_info_finish');
+Gio._promisify(Gio.File.prototype, 'query_info_async');
 
 var DEFAULT_BACKGROUND_COLOR = Clutter.Color.from_pixel(0x2e3436ff);
 
diff --git a/js/ui/components/networkAgent.js b/js/ui/components/networkAgent.js
index 8c8d8451b8..68ac05f0cc 100644
--- a/js/ui/components/networkAgent.js
+++ b/js/ui/components/networkAgent.js
@@ -10,9 +10,8 @@ const MessageTray = imports.ui.messageTray;
 const ModalDialog = imports.ui.modalDialog;
 const ShellEntry = imports.ui.shellEntry;
 
-Gio._promisify(Shell.NetworkAgent.prototype, 'init_async', 'init_finish');
-Gio._promisify(Shell.NetworkAgent.prototype,
-    'search_vpn_plugin', 'search_vpn_plugin_finish');
+Gio._promisify(Shell.NetworkAgent.prototype, 'init_async');
+Gio._promisify(Shell.NetworkAgent.prototype, 'search_vpn_plugin');
 
 const VPN_UI_GROUP = 'VPN Plugin UI';
 
diff --git a/js/ui/components/telepathyClient.js b/js/ui/components/telepathyClient.js
index 103688259c..859a7e64fb 100644
--- a/js/ui/components/telepathyClient.js
+++ b/js/ui/components/telepathyClient.js
@@ -8,13 +8,10 @@ var Tp = null;
 try {
     ({ TelepathyGLib: Tp, TelepathyLogger: Tpl } = imports.gi);
 
-    Gio._promisify(Tp.Channel.prototype, 'close_async', 'close_finish');
-    Gio._promisify(Tp.TextChannel.prototype,
-        'send_message_async', 'send_message_finish');
-    Gio._promisify(Tp.ChannelDispatchOperation.prototype,
-        'claim_with_async', 'claim_with_finish');
-    Gio._promisify(Tpl.LogManager.prototype,
-        'get_filtered_events_async', 'get_filtered_events_finish');
+    Gio._promisify(Tp.Channel.prototype, 'close_async');
+    Gio._promisify(Tp.TextChannel.prototype, 'send_message_async');
+    Gio._promisify(Tp.ChannelDispatchOperation.prototype, 'claim_with_async');
+    Gio._promisify(Tpl.LogManager.prototype, 'get_filtered_events_async');
 } catch (e) {
     log('Telepathy is not available, chat integration will be disabled.');
 }
diff --git a/js/ui/environment.js b/js/ui/environment.js
index 37c854cc36..e1225257bd 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -28,16 +28,14 @@ const { Clutter, Gio, GLib, GObject, Meta, Polkit, Shell, St } = imports.gi;
 const Gettext = imports.gettext;
 const System = imports.system;
 
-Gio._promisify(Gio.DataInputStream.prototype, 'fill_async', 'fill_finish');
-Gio._promisify(Gio.DataInputStream.prototype,
-    'read_line_async', 'read_line_finish');
-Gio._promisify(Gio.DBus, 'get', 'get_finish');
-Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
-Gio._promisify(Gio.DBusProxy, 'new', 'new_finish');
-Gio._promisify(Gio.DBusProxy.prototype, 'init_async', 'init_finish');
-Gio._promisify(Gio.DBusProxy.prototype,
-    'call_with_unix_fd_list', 'call_with_unix_fd_list_finish');
-Gio._promisify(Polkit.Permission, 'new', 'new_finish');
+Gio._promisify(Gio.DataInputStream.prototype, 'fill_async');
+Gio._promisify(Gio.DataInputStream.prototype, 'read_line_async');
+Gio._promisify(Gio.DBus, 'get');
+Gio._promisify(Gio.DBusConnection.prototype, 'call');
+Gio._promisify(Gio.DBusProxy, 'new');
+Gio._promisify(Gio.DBusProxy.prototype, 'init_async');
+Gio._promisify(Gio.DBusProxy.prototype, 'call_with_unix_fd_list');
+Gio._promisify(Polkit.Permission, 'new');
 
 let _localTimeZone = null;
 
diff --git a/js/ui/extensionDownloader.js b/js/ui/extensionDownloader.js
index 8bf4646a6a..a3cfbf3f55 100644
--- a/js/ui/extensionDownloader.js
+++ b/js/ui/extensionDownloader.js
@@ -10,14 +10,10 @@ const FileUtils = imports.misc.fileUtils;
 const Main = imports.ui.main;
 const ModalDialog = imports.ui.modalDialog;
 
-Gio._promisify(Soup.Session.prototype,
-    'send_and_read_async', 'send_and_read_finish');
-Gio._promisify(Gio.OutputStream.prototype,
-    'write_bytes_async', 'write_bytes_finish');
-Gio._promisify(Gio.IOStream.prototype,
-    'close_async', 'close_finish');
-Gio._promisify(Gio.Subprocess.prototype,
-    'wait_check_async', 'wait_check_finish');
+Gio._promisify(Soup.Session.prototype, 'send_and_read_async');
+Gio._promisify(Gio.OutputStream.prototype, 'write_bytes_async');
+Gio._promisify(Gio.IOStream.prototype, 'close_async');
+Gio._promisify(Gio.Subprocess.prototype, 'wait_check_async');
 
 var REPOSITORY_URL_DOWNLOAD = 'https://extensions.gnome.org/download-extension/%s.shell-extension.zip';
 var REPOSITORY_URL_INFO     = 'https://extensions.gnome.org/extension-info/';
diff --git a/js/ui/main.js b/js/ui/main.js
index 8fa25bc43c..ce019471b5 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -100,8 +100,8 @@ let _themeResource = null;
 let _oskResource = null;
 let _iconResource = null;
 
-Gio._promisify(Gio.File.prototype, 'delete_async', 'delete_finish');
-Gio._promisify(Gio.File.prototype, 'touch_async', 'touch_finish');
+Gio._promisify(Gio.File.prototype, 'delete_async');
+Gio._promisify(Gio.File.prototype, 'touch_async');
 
 let _remoteAccessInhibited = false;
 
diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js
index f35ab6034e..c846721aa1 100644
--- a/js/ui/screenshot.js
+++ b/js/ui/screenshot.js
@@ -10,17 +10,12 @@ const Main = imports.ui.main;
 const MessageTray = imports.ui.messageTray;
 const Workspace = imports.ui.workspace;
 
-Gio._promisify(Shell.Screenshot.prototype, 'pick_color', 'pick_color_finish');
-Gio._promisify(Shell.Screenshot.prototype, 'screenshot', 'screenshot_finish');
-Gio._promisify(Shell.Screenshot.prototype,
-    'screenshot_window', 'screenshot_window_finish');
-Gio._promisify(Shell.Screenshot.prototype,
-    'screenshot_area', 'screenshot_area_finish');
-Gio._promisify(Shell.Screenshot.prototype,
-    'screenshot_stage_to_content', 'screenshot_stage_to_content_finish');
-Gio._promisify(
-    Shell.Screenshot,
-    'composite_to_stream', 'composite_to_stream_finish');
+Gio._promisify(Shell.Screenshot.prototype, 'pick_color');
+Gio._promisify(Shell.Screenshot.prototype, 'screenshot');
+Gio._promisify(Shell.Screenshot.prototype, 'screenshot_window');
+Gio._promisify(Shell.Screenshot.prototype, 'screenshot_area');
+Gio._promisify(Shell.Screenshot.prototype, 'screenshot_stage_to_content');
+Gio._promisify(Shell.Screenshot, 'composite_to_stream');
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 const { DBusSenderChecker } = imports.misc.util;
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index dec7adc007..6fcbe67a32 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -15,10 +15,9 @@ const Util = imports.misc.util;
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
-Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
-Gio._promisify(NM.Client, 'new_async', 'new_finish');
-Gio._promisify(NM.Client.prototype,
-    'check_connectivity_async', 'check_connectivity_finish');
+Gio._promisify(Gio.DBusConnection.prototype, 'call');
+Gio._promisify(NM.Client, 'new_async');
+Gio._promisify(NM.Client.prototype, 'check_connectivity_async');
 
 const NMConnectionCategory = {
     INVALID: 'invalid',
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index d3bb155720..8f102baffb 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -46,10 +46,8 @@ const GsdWacomProxy = Gio.DBusProxy.makeProxyWrapper(GsdWacomIface);
 
 const WINDOW_DIMMER_EFFECT_NAME = "gnome-shell-window-dimmer";
 
-Gio._promisify(Shell,
-    'util_start_systemd_unit', 'util_start_systemd_unit_finish');
-Gio._promisify(Shell,
-    'util_stop_systemd_unit', 'util_stop_systemd_unit_finish');
+Gio._promisify(Shell, 'util_start_systemd_unit');
+Gio._promisify(Shell, 'util_stop_systemd_unit');
 
 var DisplayChangeDialog = GObject.registerClass(
 class DisplayChangeDialog extends ModalDialog.ModalDialog {
diff --git a/subprojects/extensions-app/js/main.js b/subprojects/extensions-app/js/main.js
index 329d3870dd..09047a939a 100644
--- a/subprojects/extensions-app/js/main.js
+++ b/subprojects/extensions-app/js/main.js
@@ -14,8 +14,8 @@ const { ExtensionState, ExtensionType } = ExtensionUtils;
 const GnomeShellIface = loadInterfaceXML('org.gnome.Shell.Extensions');
 const GnomeShellProxy = Gio.DBusProxy.makeProxyWrapper(GnomeShellIface);
 
-Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
-Gio._promisify(Shew.WindowExporter.prototype, 'export', 'export_finish');
+Gio._promisify(Gio.DBusConnection.prototype, 'call');
+Gio._promisify(Shew.WindowExporter.prototype, 'export');
 
 function loadInterfaceXML(iface) {
     const uri = 'resource:///org/gnome/Extensions/dbus-interfaces/%s.xml'.format(iface);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]