Skip to content

Commit

Permalink
Add device UUID handling and improve wired settings management
Browse files Browse the repository at this point in the history
- Introduce `device` and `uuid` properties to store network device and its UUID.
- Add logic to fetch and update the UUID of the active connection.
- Modify `open_wired_settings` to pass the UUID for editing specific connections.
- Refactor `update_wired_status` to use the stored `device` property.
- Update dialog creation to use the main application window as the parent.
  • Loading branch information
lainsce committed Sep 12, 2024
1 parent 3058aa3 commit 1147d71
Showing 1 changed file with 43 additions and 17 deletions.
60 changes: 43 additions & 17 deletions fuses/network/NetworkFuse.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class Network.NetworkFuse : Fusebox.Fuse {
private He.Switch wired_switch;
private Gtk.DropDown proxy_dropdown;

private NM.Device? device = null;
protected string uuid = "";

private string[] proxy_options = { "Off", "Manual", "Auto" };

public NetworkFuse () {
Expand All @@ -29,6 +32,18 @@ public class Network.NetworkFuse : Fusebox.Fuse {
} catch (Error e) {
warning("Failed to create NM.Client: %s", e.message);
}

foreach (var d in nm_client.get_devices()) {
if (d.get_device_type() == NM.DeviceType.ETHERNET) {
device = d;
break;
}
}

get_uuid ();
device.state_changed.connect_after (() => {
get_uuid ();
});
}

public override Gtk.Widget get_widget () {
Expand Down Expand Up @@ -87,7 +102,23 @@ public class Network.NetworkFuse : Fusebox.Fuse {
wired_block.widget = wired_box;

wired_switch.notify["active"].connect(update_wired_status);
settings_button.clicked.connect(open_wired_settings);
settings_button.clicked.connect(() => {
open_wired_settings (uuid);
});
}

private void get_uuid () {
var active_connection = device.get_active_connection ();
if (active_connection != null) {
uuid = active_connection.get_uuid ();
} else {
var available_connections = device.get_available_connections ();
if (available_connections.length > 0) {
uuid = available_connections[0].get_uuid ();
} else {
uuid = "";
}
}
}

private void create_vpn_section() {
Expand Down Expand Up @@ -136,18 +167,10 @@ public class Network.NetworkFuse : Fusebox.Fuse {
private void update_wired_status() {
if (nm_client == null) return;

NM.Device? wired_device = null;
foreach (var device in nm_client.get_devices()) {
if (device.get_device_type() == NM.DeviceType.ETHERNET) {
wired_device = device;
break;
}
}

if (wired_device != null) {
var active_connection = wired_device.get_active_connection();
if (device != null) {
var active_connection = device.get_active_connection();
if (active_connection != null) {
wired_block.subtitle = _("Connected - %u Mb/s").printf(((NM.DeviceEthernet)wired_device).get_speed());
wired_block.subtitle = _("Connected - %u Mb/s").printf(((NM.DeviceEthernet)device).get_speed());
wired_switch.iswitch.active = true;
} else {
wired_block.subtitle = _("Disconnected");
Expand Down Expand Up @@ -179,7 +202,7 @@ public class Network.NetworkFuse : Fusebox.Fuse {
private void open_manual_proxy_settings() {
var dialog = new Gtk.Dialog.with_buttons(
_("Manual Proxy Settings"),
null,
He.Misc.find_ancestor_of_type<He.ApplicationWindow> (main_box),
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR,
_("Close"),
Gtk.ResponseType.CLOSE
Expand Down Expand Up @@ -216,7 +239,7 @@ public class Network.NetworkFuse : Fusebox.Fuse {
private void open_auto_proxy_settings() {
var dialog = new Gtk.Dialog.with_buttons(
_("Automatic Proxy Settings"),
null,
He.Misc.find_ancestor_of_type<He.ApplicationWindow> (main_box),
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR,
_("Close"),
Gtk.ResponseType.CLOSE
Expand Down Expand Up @@ -248,7 +271,7 @@ public class Network.NetworkFuse : Fusebox.Fuse {
private void open_vpn_settings() {
var dialog = new Gtk.Dialog.with_buttons(
_("VPN Settings"),
null,
He.Misc.find_ancestor_of_type<He.ApplicationWindow> (main_box),
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR,
_("Close"),
Gtk.ResponseType.CLOSE
Expand Down Expand Up @@ -285,9 +308,12 @@ public class Network.NetworkFuse : Fusebox.Fuse {
dialog.present();
}

private void open_wired_settings() {
private void open_wired_settings(string uuid) {
try {
Process.spawn_command_line_async("nm-connection-editor --type=ethernet");
var appinfo = AppInfo.create_from_commandline (
"nm-connection-editor --edit=%s".printf (uuid), null, AppInfoCreateFlags.NONE
);
appinfo.launch (null, null);
} catch (Error e) {
warning("Failed to open wired settings: %s", e.message);
}
Expand Down

0 comments on commit 1147d71

Please sign in to comment.