Skip to content

Commit 98811de

Browse files
committed
Use custom server from selected subscription
1 parent 5c51832 commit 98811de

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

ntfy-daemon/src/models.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
88

99
use crate::Error;
1010

11+
pub const DEFAULT_SERVER: &str = "https://ntfy.sh";
1112
static EMOJI_MAP: OnceLock<HashMap<String, String>> = OnceLock::new();
1213

1314
fn emoji_map() -> &'static HashMap<String, String> {
@@ -188,7 +189,7 @@ pub struct SubscriptionBuilder {
188189
impl SubscriptionBuilder {
189190
pub fn new(topic: String) -> Self {
190191
Self {
191-
server: "https://ntfy.sh".to_string(),
192+
server: DEFAULT_SERVER.to_string(),
192193
topic,
193194
muted: false,
194195
archived: false,

src/widgets/add_subscription_dialog.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::cell::OnceCell;
12
use std::cell::RefCell;
23

34
use adw::prelude::*;
@@ -20,6 +21,7 @@ mod imp {
2021
#[derive(Debug, Default)]
2122
pub struct AddSubscriptionDialog {
2223
pub widgets: RefCell<Widgets>,
24+
pub init_custom_server: OnceCell<String>,
2325
}
2426

2527
#[glib::object_subclass]
@@ -47,12 +49,6 @@ mod imp {
4749
Lazy::new(|| vec![Signal::builder("subscribe-request").build()]);
4850
SIGNALS.as_ref()
4951
}
50-
51-
fn constructed(&self) {
52-
self.parent_constructed();
53-
let obj = self.obj().clone();
54-
obj.build_ui();
55-
}
5652
}
5753
impl WidgetImpl for AddSubscriptionDialog {}
5854
impl WindowImpl for AddSubscriptionDialog {}
@@ -66,8 +62,15 @@ glib::wrapper! {
6662
}
6763

6864
impl AddSubscriptionDialog {
69-
pub fn new() -> Self {
70-
glib::Object::builder().build()
65+
pub fn new(custom_server: Option<String>) -> Self {
66+
let this: Self = glib::Object::builder().build();
67+
if let Some(s) = custom_server {
68+
if s != ntfy_daemon::models::DEFAULT_SERVER {
69+
this.imp().init_custom_server.set(s).unwrap();
70+
}
71+
}
72+
this.build_ui();
73+
this
7174
}
7275
fn build_ui(&self) {
7376
let imp = self.imp();
@@ -118,10 +121,12 @@ impl AddSubscriptionDialog {
118121
},
119122
append: server_expander = &adw::ExpanderRow {
120123
set_title: "Custom server...",
121-
set_enable_expansion: false,
124+
set_enable_expansion: imp.init_custom_server.get().is_some(),
125+
set_expanded: imp.init_custom_server.get().is_some(),
122126
set_show_enable_switch: true,
123127
add_row: server_entry = &adw::EntryRow {
124128
set_title: "Server",
129+
set_text: imp.init_custom_server.get().map(|x| x.as_str()).unwrap_or(""),
125130
}
126131
}
127132
},

src/widgets/window.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ mod imp {
119119
impl NotifyWindow {
120120
#[template_callback]
121121
fn show_add_topic(&self, _btn: &gtk::Button) {
122-
let dialog = AddSubscriptionDialog::new();
122+
let this = self.obj().clone();
123+
let dialog =
124+
AddSubscriptionDialog::new(this.selected_subscription().map(|x| x.server()));
123125
dialog.set_transient_for(Some(&self.obj().clone()));
124126
dialog.present();
125127

126-
let this = self.obj().clone();
127128
let dc = dialog.clone();
128129
dialog.connect_local("subscribe-request", true, move |_| {
129130
let sub = match dc.subscription() {

0 commit comments

Comments
 (0)