Skip to content

Commit

Permalink
Allow adding new system connections without admin prompt (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter authored Jan 28, 2024
1 parent e1c1dab commit 051408b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y gobject-introspection libgranite-dev libnm-dev libnma-dev libwingpanel-dev meson valac
apt install -y gobject-introspection libgranite-dev libnm-dev libnma-dev libwingpanel-dev libpolkit-gobject-1-dev meson valac
- name: Build
env:
DESTDIR: out
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ You'll need the following dependencies:
* libgranite-dev
* libnm-dev
* libnma-dev
* libpolkit-gobject-1-dev
* libwingpanel-dev
* meson
* valac
Expand Down
7 changes: 7 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ i18n.merge_file(
install: true,
install_dir: join_paths(get_option('datadir'), 'metainfo'),
)

configure_file(
input: 'network.policy.in',
output: 'io.elementary.wingpanel.network.policy',
configuration: config_data,
install_dir: polkit_dep.get_pkgconfig_variable('policydir', define_variable: ['prefix', prefix])
)
21 changes: 21 additions & 0 deletions data/network.policy.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
<vendor>elementary</vendor>
<vendor_url>https://elementary.io/</vendor_url>

<action id="io.elementary.wingpanel.network.administration">
<description>Modify network connections for all users</description>
<message>Authentication is required to manage global network settings</message>
<icon_name>preferences-system-network</icon_name>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.imply">org.freedesktop.NetworkManager.settings.modify.system</annotate>
</action>

</policyconfig>
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ gresource = gnome.compile_resources(
source_dir: 'data'
)

polkit_dep = dependency ('polkit-gobject-1')

shared_module(
meson.project_name(),
config_file,
Expand All @@ -61,6 +63,7 @@ shared_module(
dependency('gtk+-3.0'),
dependency('libnm', version: '>=1.24'),
dependency('libnma'),
polkit_dep,
meson.get_compiler('vala').find_library('posix'),
wingpanel_dep
],
Expand Down
13 changes: 13 additions & 0 deletions src/Widgets/WifiInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

public class Network.WifiInterface : Network.WidgetNMInterface {
private static Polkit.Permission? permission = null;

public NM.Client nm_client { get; construct; }

public NM.DeviceWifi? wifi_device;
Expand Down Expand Up @@ -238,6 +240,17 @@ public class Network.WifiInterface : Network.WidgetNMInterface {
return;
}

if (permission == null) {
try {
permission = new Polkit.Permission.sync (
"io.elementary.wingpanel.network.administration",
new Polkit.UnixProcess (Posix.getpid ())
);
} catch (Error e) {
warning ("Can't get permission to add Wi-Fi network without prompting for admin: %s", e.message);
}
}

// See if we already have a connection configured for this AP and try connecting if so
var connections = nm_client.get_connections ();
var device_connections = wifi_device.filter_connections (connections);
Expand Down

0 comments on commit 051408b

Please sign in to comment.