From c10087a55d5f6c7bb632bc4ba085043ea7ad2d28 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Sat, 7 Jan 2023 00:21:16 -0500 Subject: [PATCH] feat: more improvements to network applet --- Cargo.lock | 261 +++++++++++++----- Cargo.toml | 3 - cosmic-applet-network/Cargo.toml | 5 +- cosmic-applet-network/src/app.rs | 141 ++++++---- .../src/network_manager/available_wifi.rs | 20 +- .../src/network_manager/mod.rs | 61 +++- 6 files changed, 363 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 632d1e82..f13c5529 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] name = "ab_glyph" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcdbc68024b653943864d436fe8a24b028095bc1cf91a8926f8241e4aaffe59" +checksum = "e5568a4aa5ba8adf5175c5c460b030e27d8893412976cc37bef0e4fbc16cfbba" dependencies = [ "ab_glyph_rasterizer", "owned_ttf_parser", @@ -208,9 +208,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" [[package]] name = "async-trait" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" +checksum = "705339e0e4a9690e2908d2b3d049d85682cf19fbd5782494498fbf7003a6a282" dependencies = [ "proc-macro2", "quote", @@ -551,7 +551,7 @@ dependencies = [ "rust-embed", "smithay-client-toolkit", "tokio", - "zbus", + "zbus 3.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -560,7 +560,7 @@ version = "0.1.0" dependencies = [ "libcosmic", "smithay-client-toolkit", - "zbus", + "zbus 3.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -581,7 +581,7 @@ dependencies = [ "slotmap", "smithay-client-toolkit", "tokio", - "zbus", + "zbus 3.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -605,7 +605,7 @@ dependencies = [ "nix 0.26.1", "smithay-client-toolkit", "tokio", - "zbus", + "zbus 3.7.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", ] [[package]] @@ -655,20 +655,20 @@ dependencies = [ [[package]] name = "cosmic-dbus-networkmanager" version = "0.1.0" -source = "git+https://github.com/pop-os/dbus-settings-bindings?branch=deps#af1cc089ec08f4cb37d7d9448523963bf05995c6" +source = "git+https://github.com/pop-os/dbus-settings-bindings?branch=main#5adeb6dc11fd11d26d09ec35c25b93866bb21d31" dependencies = [ "bitflags", "derive_builder", "procfs", "time 0.3.17", - "zbus", - "zvariant 3.9.0", + "zbus 3.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zvariant 3.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#bab60b3883bd90b71b1be8bdf771fa11be0cf1dc" +source = "git+https://github.com/pop-os/cosmic-panel#b4e60dc30bb798d59cc57957291609e794d38821" dependencies = [ "anyhow", "ron", @@ -1556,6 +1556,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "getrandom" version = "0.2.8" @@ -1996,7 +2006,7 @@ dependencies = [ [[package]] name = "iced" version = "0.6.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "iced_core", "iced_futures", @@ -2004,7 +2014,7 @@ dependencies = [ "iced_graphics", "iced_native", "iced_sctk", - "iced_swbuf", + "iced_softbuffer", "iced_wgpu", "image", "thiserror", @@ -2013,7 +2023,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.6.2" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "bitflags", "palette", @@ -2023,7 +2033,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.5.1" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "futures", "log", @@ -2035,7 +2045,7 @@ dependencies = [ [[package]] name = "iced_glow" version = "0.5.1" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "bytemuck", "euclid", @@ -2050,7 +2060,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.5.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "bitflags", "bytemuck", @@ -2070,7 +2080,7 @@ dependencies = [ [[package]] name = "iced_lazy" version = "0.3.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "iced_native", "ouroboros 0.13.0", @@ -2079,7 +2089,7 @@ dependencies = [ [[package]] name = "iced_native" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "iced_core", "iced_futures", @@ -2093,7 +2103,7 @@ dependencies = [ [[package]] name = "iced_sctk" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "enum-repr", "futures", @@ -2110,19 +2120,9 @@ dependencies = [ ] [[package]] -name = "iced_style" -version = "0.5.1" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" -dependencies = [ - "iced_core", - "once_cell", - "palette", -] - -[[package]] -name = "iced_swbuf" +name = "iced_softbuffer" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "cosmic-text", "iced_graphics", @@ -2134,10 +2134,20 @@ dependencies = [ "softbuffer", ] +[[package]] +name = "iced_style" +version = "0.5.1" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" +dependencies = [ + "iced_core", + "once_cell", + "palette", +] + [[package]] name = "iced_wgpu" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "bitflags", "bytemuck", @@ -2327,7 +2337,7 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=master#357de5e9be4110fa3762cd7ec057760353505620" +source = "git+https://github.com/pop-os/libcosmic/?branch=master#5224c9b75c000fcf92a1851391fe1dc82486610a" dependencies = [ "apply", "cosmic-panel-config", @@ -2470,7 +2480,7 @@ version = "3.0.3" source = "git+https://github.com/pop-os/logind-zbus?branch=main#0789bde15b61b3f65b1e028841eeb5411f66f474" dependencies = [ "serde", - "zbus", + "zbus 3.7.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", ] [[package]] @@ -2841,11 +2851,11 @@ dependencies = [ [[package]] name = "owned_ttf_parser" -version = "0.17.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18904d3c65493a9f0d7542293d1a7f69bfdc309a6b9ef4f46dc3e58b0577edc5" +checksum = "2a5f3c7ca08b6879e7965fb25e24d1f5eeb32ea73f9ad99b3854778a38c57e93" dependencies = [ - "ttf-parser 0.17.1", + "ttf-parser 0.18.0", ] [[package]] @@ -3690,12 +3700,17 @@ dependencies = [ [[package]] name = "softbuffer" -version = "0.1.1" -source = "git+https://github.com/rust-windowing/softbuffer?rev=d5bb2c1#d5bb2c1c78811854d11225ff7cc29f0062781333" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3177eca2c15033e254b9b70c4915150200b1cf6fa777de18be9977ae5850077f" dependencies = [ + "bytemuck", + "cfg_aliases", "cocoa", "core-graphics", + "fastrand", "foreign-types", + "log", "nix 0.26.1", "objc", "raw-window-handle", @@ -3708,6 +3723,7 @@ dependencies = [ "web-sys", "windows-sys 0.42.0", "x11-dl", + "x11rb", ] [[package]] @@ -3952,9 +3968,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.23.1" +version = "1.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a54aca0c15d014013256222ba0ebed095673f89345dd79119d912eb561b7a8" +checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae" dependencies = [ "autocfg", "bytes", @@ -4035,6 +4051,12 @@ version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" +[[package]] +name = "ttf-parser" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf554b6e535f9a160b2ed4ea83f99000f21cbc0a693df26e258eaf2c226a151" + [[package]] name = "twox-hash" version = "1.6.3" @@ -4598,6 +4620,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4715,6 +4746,31 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "x11rb" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdf3c79412dd91bae7a7366b8ad1565a85e35dd049affc3a6a2c549e97419617" +dependencies = [ + "gethostname", + "libc", + "libloading", + "nix 0.25.1", + "once_cell", + "winapi", + "winapi-wsapoll", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0b1513b141123073ce54d5bb1d33f801f17508fbd61e02060b1214e96d39c56" +dependencies = [ + "nix 0.25.1", +] + [[package]] name = "xcursor" version = "0.3.4" @@ -4736,7 +4792,7 @@ dependencies = [ [[package]] name = "xdg-shell-wrapper-config" version = "0.1.0" -source = "git+https://github.com/pop-os/xdg-shell-wrapper#82ce268c9c560be3728190a2255c849d3bae77e7" +source = "git+https://github.com/pop-os/xdg-shell-wrapper#95f6a663e383d3f6f13f689f9e9d7e691b9fe28b" dependencies = [ "serde", "wayland-protocols-wlr", @@ -4784,8 +4840,9 @@ checksum = "c03b3e19c937b5b9bd8e52b1c88f30cce5c0d33d676cf174866175bb794ff658" [[package]] name = "zbus" -version = "3.6.2" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#0b623738048395cdf398c18be24c9f00d8fdab58" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "379d587c0ccb632d1179cf44082653f682842f0535f0fdfaefffc34849cc855e" dependencies = [ "async-broadcast", "async-executor", @@ -4816,15 +4873,65 @@ dependencies = [ "tracing", "uds_windows", "winapi", - "zbus_macros", - "zbus_names", - "zvariant 3.10.0", + "zbus_macros 3.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zbus_names 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zvariant 3.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zbus" +version = "3.7.0" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#e90e72eb2d0d5f77144bf40baa7337de89932a53" +dependencies = [ + "async-broadcast", + "async-executor", + "async-io", + "async-lock", + "async-recursion", + "async-task", + "async-trait", + "byteorder", + "derivative", + "dirs 4.0.0", + "enumflags2", + "event-listener", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "nix 0.25.1", + "once_cell", + "ordered-stream", + "rand", + "serde", + "serde_repr", + "sha1", + "static_assertions", + "tracing", + "uds_windows", + "winapi", + "zbus_macros 3.7.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", + "zbus_names 2.5.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", + "zvariant 3.10.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", ] [[package]] name = "zbus_macros" -version = "3.6.2" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#0b623738048395cdf398c18be24c9f00d8fdab58" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66492a2e90c0df7190583eccb8424aa12eb7ff06edea415a4fff6688fae18cf8" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "zbus_macros" +version = "3.7.0" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#e90e72eb2d0d5f77144bf40baa7337de89932a53" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -4836,11 +4943,22 @@ dependencies = [ [[package]] name = "zbus_names" version = "2.5.0" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#0b623738048395cdf398c18be24c9f00d8fdab58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f34f314916bd89bdb9934154627fab152f4f28acdda03e7c4c68181b214fe7e3" dependencies = [ "serde", "static_assertions", - "zvariant 3.10.0", + "zvariant 3.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zbus_names" +version = "2.5.0" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#e90e72eb2d0d5f77144bf40baa7337de89932a53" +dependencies = [ + "serde", + "static_assertions", + "zvariant 3.10.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", ] [[package]] @@ -4849,37 +4967,38 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c110ba09c9b3a43edd4803d570df0da2414fed6e822e22b976a4e3ef50860701" -[[package]] -name = "zvariant" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f8c89c183461e11867ded456db252eae90874bc6769b7adbea464caa777e51" -dependencies = [ - "byteorder", - "libc", - "serde", - "static_assertions", - "zvariant_derive 3.9.0", -] - [[package]] name = "zvariant" version = "3.10.0" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#0b623738048395cdf398c18be24c9f00d8fdab58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576cc41e65c7f283e5460f5818073e68fb1f1631502b969ef228c2e03c862efb" dependencies = [ "byteorder", "enumflags2", "libc", "serde", "static_assertions", - "zvariant_derive 3.10.0", + "zvariant_derive 3.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zvariant" +version = "3.10.0" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#e90e72eb2d0d5f77144bf40baa7337de89932a53" +dependencies = [ + "byteorder", + "enumflags2", + "libc", + "serde", + "static_assertions", + "zvariant_derive 3.10.0 (git+https://gitlab.freedesktop.org/dbus/zbus?branch=main)", ] [[package]] name = "zvariant_derive" -version = "3.9.0" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "155247a5d1ab55e335421c104ccd95d64f17cebbd02f50cdbc1c33385f9c4d81" +checksum = "0fd4aafc0dee96ae7242a24249ce9babf21e1562822f03df650d4e68c20e41ed" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -4890,7 +5009,7 @@ dependencies = [ [[package]] name = "zvariant_derive" version = "3.10.0" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#0b623738048395cdf398c18be24c9f00d8fdab58" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?branch=main#e90e72eb2d0d5f77144bf40baa7337de89932a53" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 98eaaa3b..5d506a12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,5 @@ members = [ "cosmic-applet-workspaces", ] -[patch.crates-io] -zbus = {git = "https://gitlab.freedesktop.org/dbus/zbus", branch = "main"} - [profile.release] lto = "fat" diff --git a/cosmic-applet-network/Cargo.toml b/cosmic-applet-network/Cargo.toml index a1b75f8e..7b610e40 100644 --- a/cosmic-applet-network/Cargo.toml +++ b/cosmic-applet-network/Cargo.toml @@ -6,12 +6,13 @@ license = "GPL-3.0-or-later" [dependencies] once_cell = "1.16.0" -cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings", branch = "deps" } +cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings", branch = "main" } +# cosmic-dbus-networkmanager = { path = "../../../dbus-settings-bindings/networkmanager" } futures-util = "0.3.21" libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet", "tokio"] } sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "3776d4a" } futures = "0.3" -zbus = { version = "3.6.2", no-default-features = true } +zbus = { version = "3.7", no-default-features = true } log = "0.4" pretty_env_logger = "0.4" # Application i18n diff --git a/cosmic-applet-network/src/app.rs b/cosmic-applet-network/src/app.rs index b81506d7..bd4c13a5 100644 --- a/cosmic-applet-network/src/app.rs +++ b/cosmic-applet-network/src/app.rs @@ -30,7 +30,7 @@ use cosmic::{ }, }, }; -use cosmic_dbus_networkmanager::access_point; +use cosmic_dbus_networkmanager::{access_point, interface::enums::DeviceState}; use futures::channel::mpsc::UnboundedSender; use crate::{ @@ -80,6 +80,7 @@ struct CosmicNetworkApplet { wifi: bool, wireless_access_points: Vec, active_conns: Vec, + known_access_points: Vec, nm_sender: Option>, show_visible_networks: bool, new_connection: Option, @@ -109,6 +110,7 @@ impl CosmicNetworkApplet { #[derive(Debug, Clone)] enum Message { + ActivateKnownWifi(String), TogglePopup, ToggleAirplaneMode(bool), ToggleWiFi(bool), @@ -185,6 +187,7 @@ impl Application for CosmicNetworkApplet { sender, wireless_access_points, active_conns, + known_access_points, wifi_enabled, airplane_mode, } => { @@ -194,6 +197,7 @@ impl Application for CosmicNetworkApplet { self.wifi = wifi_enabled; self.airplane_mode = airplane_mode; self.update_icon_name(); + self.known_access_points = known_access_points; } NetworkManagerEvent::WiFiEnabled(enabled) => { self.wifi = enabled; @@ -222,11 +226,6 @@ impl Application for CosmicNetworkApplet { } }, Message::SelectWirelessAccessPoint(access_point) => { - // if let Some(tx) = self.nm_sender.as_ref() { - // let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint( - // access_point.ssid.clone(), - // )); - // } self.new_connection .replace(NewConnectionState::EnterPassword { access_point, @@ -237,26 +236,28 @@ impl Application for CosmicNetworkApplet { self.new_connection.take(); self.show_visible_networks = !self.show_visible_networks; } - Message::Password(entered_pw) => { - dbg!(&entered_pw); - - match &mut self.new_connection { - Some(NewConnectionState::EnterPassword { password, .. }) => { - *password = entered_pw; - } - _ => {} + Message::Password(entered_pw) => match &mut self.new_connection { + Some(NewConnectionState::EnterPassword { password, .. }) => { + *password = entered_pw; } - } + _ => {} + }, Message::SubmitPassword => { // TODO setup connection match self.new_connection.take() { Some(new_connection) => { - self.new_connection - .replace(NewConnectionState::Failure(new_connection.into())); + let ap: AccessPoint = new_connection.into(); + if let Some(tx) = self.nm_sender.as_ref() { + let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint( + ap.ssid.clone(), + )); + } + self.new_connection.replace(NewConnectionState::Failure(ap)); } None => {} } } + Message::ActivateKnownWifi(ssid) => {} Message::CancelNewConnection => { self.new_connection.take(); } @@ -282,9 +283,10 @@ impl Application for CosmicNetworkApplet { .on_press(Message::TogglePopup) .into(), SurfaceIdWrapper::Popup(_) => { - let mut list_col = column![]; + let mut vpn_ethernet_col = column![]; + let mut known_wifi = column![]; for conn in &self.active_conns { - let el = match conn { + match conn { ActiveConnectionInfo::Vpn { name, ip_addresses } => { let mut ipv4 = column![]; for addr in ip_addresses { @@ -295,10 +297,11 @@ impl Application for CosmicNetworkApplet { .size(12), ); } - std::net::IpAddr::V6(a) => {} + std::net::IpAddr::V6(_) => {} } } - column![text(name), ipv4].spacing(4) + vpn_ethernet_col = + vpn_ethernet_col.push(column![text(name), ipv4].spacing(4)); } ActiveConnectionInfo::Wired { name, @@ -318,15 +321,17 @@ impl Application for CosmicNetworkApplet { std::net::IpAddr::V6(a) => {} } } - column![ - row![ - text(name), - text(format!("{speed} {}", fl!("megabits-per-second"))) + vpn_ethernet_col = vpn_ethernet_col.push( + column![ + row![ + text(name), + text(format!("{speed} {}", fl!("megabits-per-second"))) + ] + .spacing(16), + ipv4, ] - .spacing(16), - ipv4, - ] - .spacing(4) + .spacing(4), + ); } ActiveConnectionInfo::WiFi { name, ip_addresses, .. @@ -340,10 +345,10 @@ impl Application for CosmicNetworkApplet { .size(12), ); } - std::net::IpAddr::V6(a) => {} + std::net::IpAddr::V6(_) => {} } } - column![button(Button::Secondary) + known_wifi = known_wifi.push(column![button(Button::Secondary) .custom(vec![ icon("network-wireless-symbolic", 24) .style(Svg::Custom(|theme| svg::Appearance { @@ -362,14 +367,46 @@ impl Application for CosmicNetworkApplet { .into() ]) .padding([8, 24]) - .style(button_style.clone()) - .on_press(Message::Ignore)] + .style(button_style.clone())]); } }; - list_col = list_col.push(el); + } + for known in &self.known_access_points { + let mut btn = button(Button::Secondary) + .custom(vec![ + icon("network-wireless-symbolic", 24) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(24)) + .height(Length::Units(24)) + .into(), + text(&known.ssid).size(14).into(), + ]) + .padding([8, 24]) + .width(Length::Fill) + .style(button_style.clone()); + let btn = match known.state { + // DeviceState::Prepare => todo!(), + // DeviceState::Config => todo!(), + // DeviceState::NeedAuth => todo!(), + // DeviceState::IpConfig => todo!(), + // DeviceState::IpCheck => todo!(), + // DeviceState::Secondaries => todo!(), + DeviceState::Failed + | DeviceState::Unknown + | DeviceState::Unmanaged + | DeviceState::Disconnected + | DeviceState::NeedAuth => { + btn.on_press(Message::ActivateKnownWifi(known.ssid.clone())) + } + _ => btn, + }; + known_wifi = known_wifi.push(row![btn].align_items(Alignment::Center)); } let mut content = column![ + vpn_ethernet_col, container( toggler(fl!("airplane-mode"), self.airplane_mode, |m| { Message::ToggleAirplaneMode(m) @@ -384,7 +421,7 @@ impl Application for CosmicNetworkApplet { ) .padding([0, 12]), horizontal_rule(1), - list_col, + known_wifi, ] .align_items(Alignment::Center) .spacing(8) @@ -456,11 +493,11 @@ impl Application for CosmicNetworkApplet { .padding([0, 24]) .into()]) .on_press(Message::CancelNewConnection), - button(Button::Secondary).custom(vec![container(text( - fl!("connect") - )) - .padding([0, 24]) - .into()]) + button(Button::Secondary) + .custom(vec![container(text(fl!("connect"))) + .padding([0, 24]) + .into()]) + .on_press(Message::SubmitPassword) ] .spacing(24) ] @@ -470,19 +507,27 @@ impl Application for CosmicNetworkApplet { content = content.push(col); } NewConnectionState::Waiting(access_point) => { - let connecting = row![ + let id = row![ icon("network-wireless-symbolic", 24) .style(Svg::Custom(|theme| svg::Appearance { color: Some(theme.palette().text), })) .width(Length::Units(24)) .height(Length::Units(24)), - text(format!("{}", fl!("connecting"))) - .size(14) - .width(Length::Fill) - .height(Length::Units(24)) - .horizontal_alignment(Horizontal::Right) - .vertical_alignment(Vertical::Center) + text(&access_point.ssid).size(14), + ] + .align_items(Alignment::Center) + .width(Length::Fill) + .padding([0, 24]) + .spacing(12); + let connecting = row![ + id, + icon("process-working-symbolic", 24) + .style(Svg::Custom(|theme| svg::Appearance { + color: Some(theme.palette().text), + })) + .width(Length::Units(24)) + .height(Length::Units(24)), ]; content = content.push(connecting); } @@ -499,7 +544,7 @@ impl Application for CosmicNetworkApplet { .align_items(Alignment::Center) .width(Length::Fill) .padding([0, 24]) - .spacing(8); + .spacing(12); content = content.push(id); let col = column![ text(fl!("unable-to-connect")), diff --git a/cosmic-applet-network/src/network_manager/available_wifi.rs b/cosmic-applet-network/src/network_manager/available_wifi.rs index d1018822..7f9f5c83 100644 --- a/cosmic-applet-network/src/network_manager/available_wifi.rs +++ b/cosmic-applet-network/src/network_manager/available_wifi.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use cosmic_dbus_networkmanager::device::wireless::WirelessDevice; +use cosmic_dbus_networkmanager::{device::wireless::WirelessDevice, interface::enums::DeviceState}; use futures_util::StreamExt; use itertools::Itertools; @@ -16,17 +16,32 @@ pub async fn handle_wireless_device(device: WirelessDevice<'_>) -> zbus::Result< } } let access_points = device.get_access_points().await?; + let state: DeviceState = device + .upcast() + .await + .and_then(|dev| dev.cached_state()) + .unwrap_or_default() + .map(|s| s.into()) + .unwrap_or_else(|| DeviceState::Unknown); // Sort by strength and remove duplicates let mut aps = HashMap::::new(); for ap in access_points { let ssid = String::from_utf8_lossy(&ap.ssid().await?.clone()).into_owned(); let strength = ap.strength().await?; + if let Some(access_point) = aps.get(&ssid) { if access_point.strength > strength { continue; } } - aps.insert(ssid.clone(), AccessPoint { ssid, strength }); + aps.insert( + ssid.clone(), + AccessPoint { + ssid, + strength, + state: state, + }, + ); } let aps = aps .into_iter() @@ -40,4 +55,5 @@ pub async fn handle_wireless_device(device: WirelessDevice<'_>) -> zbus::Result< pub struct AccessPoint { pub ssid: String, pub strength: u8, + pub state: DeviceState, } diff --git a/cosmic-applet-network/src/network_manager/mod.rs b/cosmic-applet-network/src/network_manager/mod.rs index 615467f3..5d0c8951 100644 --- a/cosmic-applet-network/src/network_manager/mod.rs +++ b/cosmic-applet-network/src/network_manager/mod.rs @@ -5,10 +5,17 @@ use std::{fmt::Debug, hash::Hash, time::Duration}; use cosmic::iced::{self, subscription}; use cosmic_dbus_networkmanager::{ - device::SpecificDevice, interface::enums::DeviceType, nm::NetworkManager, + device::SpecificDevice, + interface::{enums::DeviceType, settings::connection::ConnectionSettingsProxy}, + nm::NetworkManager, + settings::{ + connection::{ConnectionSettings, Secrets, Settings}, + NetworkManagerSettings, + }, }; use futures::{ channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}, + future::ok, FutureExt, StreamExt, }; use zbus::Connection; @@ -49,6 +56,12 @@ async fn start_listening( Ok(n) => n, Err(_) => return (None, State::Finished), }; + let s = match NetworkManagerSettings::new(&conn).await { + Ok(s) => s, + Err(_) => return (None, State::Finished), + }; + let known_conns = s.list_connections().await.unwrap_or_default(); + let (tx, rx) = unbounded(); let mut active_conns = active_connections( network_manager @@ -85,8 +98,30 @@ async fn start_listening( let mut wireless_access_points = Vec::with_capacity(wireless_access_point_futures.len()); for f in wireless_access_point_futures { - wireless_access_points.append(&mut f.await); + let mut access_points = f.await; + wireless_access_points.append(&mut access_points); } + let mut known_ssid = Vec::with_capacity(known_conns.len()); + for c in known_conns { + let s = c.get_settings().await.unwrap(); + let s = Settings::new(s); + if let Some(cur_ssid) = s + .wifi + .clone() + .and_then(|w| w.ssid) + .and_then(|ssid| String::from_utf8(ssid).ok()) + { + known_ssid.push(cur_ssid); + } + } + let known_access_points: Vec<_> = wireless_access_points + .iter() + .filter(|a| { + known_ssid.contains(&a.ssid) + && !active_conns.iter().any(|ac| ac.name() == a.ssid) + }) + .cloned() + .collect(); wireless_access_points.sort_by(|a, b| b.strength.cmp(&a.strength)); drop(network_manager); return ( @@ -97,6 +132,7 @@ async fn start_listening( wireless_access_points, wifi_enabled, airplane_mode: false, + known_access_points, active_conns, }, )), @@ -108,6 +144,7 @@ async fn start_listening( Ok(n) => n, Err(_) => return (None, State::Finished), }; + let mut active_conns_changed = tokio::time::sleep(Duration::from_secs(5)) .then(|_| async { network_manager.receive_active_connections_changed().await }) .await; @@ -153,7 +190,26 @@ async fn start_listening( Some(NetworkManagerRequest::SelectAccessPoint(ssid)) => { 'device_loop: for device in network_manager.devices().await.ok().unwrap_or_default() { if matches!(device.device_type().await.unwrap_or(DeviceType::Other), DeviceType::Wifi) { + let connection_settings = NetworkManagerSettings::new(&conn).await.unwrap(); + for conn in connection_settings.list_connections().await.unwrap() { + let s = conn.get_settings().await.unwrap(); + let s = Settings::new(s); + + let cur_ssid = s + .wifi + .clone() + .and_then(|w| w.ssid) + .and_then(|ssid| String::from_utf8(ssid).ok()); + if cur_ssid.as_ref() == Some(&ssid) { + // dbg!(s); + // dbg!(conn.get_secrets("connection").await); + // dbg!(Secrets::new(&conn).await); + // dbg!(psk); + // connection update can be used to set password + } + } for conn in device.available_connections().await.unwrap_or_default() { + // network_manager.activate_connection(conn, device.clone()); // dbg!(&conn.path()); // TODO activate connection } @@ -225,6 +281,7 @@ pub enum NetworkManagerEvent { sender: UnboundedSender, wireless_access_points: Vec, active_conns: Vec, + known_access_points: Vec, wifi_enabled: bool, airplane_mode: bool, },