From c9708b140ce046d8df95a069f7bf55405a237ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 31 Jul 2020 20:40:36 +0200 Subject: [PATCH] status/network: Use D-Bus to launch Settings panels For more obscure network configurations, we need to launch the corresponding Settings panel with additional parameters, so we cannot simply launch the .desktop file. However we can do better than spawning a command line: Control center exposes an application action we can use instead, so the process is launched with the appropriate activation environment and startup notification support. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1385 --- js/ui/status/network.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 642e1a104..3d4acd5b0 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -15,6 +15,7 @@ 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'); @@ -82,6 +83,30 @@ function ensureActiveConnectionProps(active) { } } +function launchSettingsPanel(panel, ...args) { + const param = new GLib.Variant('(sav)', + [panel, args.map(s => new GLib.Variant('s', s))]); + const platformData = { + 'desktop-startup-id': new GLib.Variant('s', + '_TIME%s'.format(global.get_current_time())), + }; + try { + Gio.DBus.session.call( + 'org.gnome.ControlCenter', + '/org/gnome/ControlCenter', + 'org.freedesktop.Application', + 'ActivateAction', + new GLib.Variant('(sava{sv})', + ['launch-panel', [param], platformData]), + null, + Gio.DBusCallFlags.NONE, + -1, + null); + } catch (e) { + log('Failed to launch Settings panel: %s'.format(e.message)); + } +} + var NMConnectionItem = class { constructor(section, connection) { this._section = section; @@ -539,8 +564,7 @@ var NMDeviceModem = class extends NMConnectionDevice { } _autoConnect() { - Util.spawn(['gnome-control-center', 'network', - 'connect-3g', this._device.get_path()]); + launchSettingsPanel('network', 'connect-3g', this._device.get_path()); } destroy() { @@ -931,8 +955,8 @@ class NMWirelessDialog extends ModalDialog.ModalDialog { (accessPoints[0]._secType == NMAccessPointSecurity.WPA_ENT)) { // 802.1x-enabled APs require further configuration, so they're // handled in gnome-control-center - Util.spawn(['gnome-control-center', 'wifi', 'connect-8021x-wifi', - this._device.get_path(), accessPoints[0].get_path()]); + launchSettingsPanel('wifi', 'connect-8021x-wifi', + this._device.get_path(), accessPoints[0].get_path()); } else { let connection = new NM.SimpleConnection(); this._client.add_and_activate_connection_async(connection, this._device, accessPoints[0].get_path(), null, null);