chore: open network settings when the button is pressed
This commit is contained in:
parent
13f4757a3f
commit
ce479f1b44
1 changed files with 39 additions and 2 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
use cosmic::app::Command;
|
use cosmic::app::Command;
|
||||||
|
use cosmic::applet::token::subscription::{
|
||||||
|
activation_token_subscription, TokenRequest, TokenUpdate,
|
||||||
|
};
|
||||||
use cosmic::applet::{menu_button, menu_control_padding, padded_control};
|
use cosmic::applet::{menu_button, menu_control_padding, padded_control};
|
||||||
|
use cosmic::cctk::sctk::reexports::calloop;
|
||||||
use cosmic::iced_widget::Row;
|
use cosmic::iced_widget::Row;
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{
|
iced::{
|
||||||
|
|
@ -93,6 +97,7 @@ struct CosmicNetworkApplet {
|
||||||
conn: Option<Connection>,
|
conn: Option<Connection>,
|
||||||
timeline: Timeline,
|
timeline: Timeline,
|
||||||
toggle_wifi_ctr: u128,
|
toggle_wifi_ctr: u128,
|
||||||
|
token_tx: Option<calloop::channel::Sender<TokenRequest>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wifi_icon(strength: u8) -> &'static str {
|
fn wifi_icon(strength: u8) -> &'static str {
|
||||||
|
|
@ -181,6 +186,8 @@ pub(crate) enum Message {
|
||||||
Password(String),
|
Password(String),
|
||||||
SubmitPassword,
|
SubmitPassword,
|
||||||
Frame(Instant),
|
Frame(Instant),
|
||||||
|
Token(TokenUpdate),
|
||||||
|
OpenSettings,
|
||||||
// Errored(String),
|
// Errored(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,6 +202,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
||||||
Self {
|
Self {
|
||||||
core,
|
core,
|
||||||
icon_name: "network-offline-symbolic".to_string(),
|
icon_name: "network-offline-symbolic".to_string(),
|
||||||
|
token_tx: None,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Command::none(),
|
Command::none(),
|
||||||
|
|
@ -392,6 +400,32 @@ impl cosmic::Application for CosmicNetworkApplet {
|
||||||
self.popup = None;
|
self.popup = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::OpenSettings => {
|
||||||
|
let exec = "cosmic-settings network".to_string();
|
||||||
|
if let Some(tx) = self.token_tx.as_ref() {
|
||||||
|
let _ = tx.send(TokenRequest {
|
||||||
|
app_id: Self::APP_ID.to_string(),
|
||||||
|
exec,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Message::Token(u) => match u {
|
||||||
|
TokenUpdate::Init(tx) => {
|
||||||
|
self.token_tx = Some(tx);
|
||||||
|
}
|
||||||
|
TokenUpdate::Finished => {
|
||||||
|
self.token_tx = None;
|
||||||
|
}
|
||||||
|
TokenUpdate::ActivationToken { token, .. } => {
|
||||||
|
let mut cmd = std::process::Command::new("cosmic-settings");
|
||||||
|
cmd.arg("network");
|
||||||
|
if let Some(token) = token {
|
||||||
|
cmd.env("XDG_ACTIVATION_TOKEN", &token);
|
||||||
|
cmd.env("DESKTOP_STARTUP_ID", &token);
|
||||||
|
}
|
||||||
|
cosmic::process::spawn(cmd);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
|
|
@ -772,7 +806,8 @@ impl cosmic::Application for CosmicNetworkApplet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content = content.push(padded_control(divider::horizontal::default()));
|
content = content.push(padded_control(divider::horizontal::default()));
|
||||||
content = content.push(menu_button(text(fl!("settings")).size(14)));
|
content = content
|
||||||
|
.push(menu_button(text(fl!("settings")).size(14)).on_press(Message::OpenSettings));
|
||||||
self.core
|
self.core
|
||||||
.applet
|
.applet
|
||||||
.popup_container(content.padding([8, 0, 8, 0]))
|
.popup_container(content.padding([8, 0, 8, 0]))
|
||||||
|
|
@ -785,12 +820,14 @@ impl cosmic::Application for CosmicNetworkApplet {
|
||||||
.timeline
|
.timeline
|
||||||
.as_subscription()
|
.as_subscription()
|
||||||
.map(|(_, now)| Message::Frame(now));
|
.map(|(_, now)| Message::Frame(now));
|
||||||
|
let token_sub = activation_token_subscription(0).map(Message::Token);
|
||||||
|
|
||||||
if let Some(conn) = self.conn.as_ref() {
|
if let Some(conn) = self.conn.as_ref() {
|
||||||
let has_popup = self.popup.is_some();
|
let has_popup = self.popup.is_some();
|
||||||
Subscription::batch(vec![
|
Subscription::batch(vec![
|
||||||
timeline,
|
timeline,
|
||||||
network_sub,
|
network_sub,
|
||||||
|
token_sub,
|
||||||
active_conns_subscription(self.toggle_wifi_ctr, conn.clone())
|
active_conns_subscription(self.toggle_wifi_ctr, conn.clone())
|
||||||
.map(Message::NetworkManagerEvent),
|
.map(Message::NetworkManagerEvent),
|
||||||
devices_subscription(self.toggle_wifi_ctr, has_popup, conn.clone())
|
devices_subscription(self.toggle_wifi_ctr, has_popup, conn.clone())
|
||||||
|
|
@ -799,7 +836,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
||||||
.map(Message::NetworkManagerEvent),
|
.map(Message::NetworkManagerEvent),
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
Subscription::batch(vec![timeline, network_sub])
|
Subscription::batch(vec![timeline, network_sub, token_sub])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue