Use custom server from selected subscription
This commit is contained in:
@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
|
pub const DEFAULT_SERVER: &str = "https://ntfy.sh";
|
||||||
static EMOJI_MAP: OnceLock<HashMap<String, String>> = OnceLock::new();
|
static EMOJI_MAP: OnceLock<HashMap<String, String>> = OnceLock::new();
|
||||||
|
|
||||||
fn emoji_map() -> &'static HashMap<String, String> {
|
fn emoji_map() -> &'static HashMap<String, String> {
|
||||||
@ -188,7 +189,7 @@ pub struct SubscriptionBuilder {
|
|||||||
impl SubscriptionBuilder {
|
impl SubscriptionBuilder {
|
||||||
pub fn new(topic: String) -> Self {
|
pub fn new(topic: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
server: "https://ntfy.sh".to_string(),
|
server: DEFAULT_SERVER.to_string(),
|
||||||
topic,
|
topic,
|
||||||
muted: false,
|
muted: false,
|
||||||
archived: false,
|
archived: false,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use std::cell::OnceCell;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
@ -20,6 +21,7 @@ mod imp {
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AddSubscriptionDialog {
|
pub struct AddSubscriptionDialog {
|
||||||
pub widgets: RefCell<Widgets>,
|
pub widgets: RefCell<Widgets>,
|
||||||
|
pub init_custom_server: OnceCell<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
@ -47,12 +49,6 @@ mod imp {
|
|||||||
Lazy::new(|| vec![Signal::builder("subscribe-request").build()]);
|
Lazy::new(|| vec![Signal::builder("subscribe-request").build()]);
|
||||||
SIGNALS.as_ref()
|
SIGNALS.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constructed(&self) {
|
|
||||||
self.parent_constructed();
|
|
||||||
let obj = self.obj().clone();
|
|
||||||
obj.build_ui();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl WidgetImpl for AddSubscriptionDialog {}
|
impl WidgetImpl for AddSubscriptionDialog {}
|
||||||
impl WindowImpl for AddSubscriptionDialog {}
|
impl WindowImpl for AddSubscriptionDialog {}
|
||||||
@ -66,8 +62,15 @@ glib::wrapper! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AddSubscriptionDialog {
|
impl AddSubscriptionDialog {
|
||||||
pub fn new() -> Self {
|
pub fn new(custom_server: Option<String>) -> Self {
|
||||||
glib::Object::builder().build()
|
let this: Self = glib::Object::builder().build();
|
||||||
|
if let Some(s) = custom_server {
|
||||||
|
if s != ntfy_daemon::models::DEFAULT_SERVER {
|
||||||
|
this.imp().init_custom_server.set(s).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.build_ui();
|
||||||
|
this
|
||||||
}
|
}
|
||||||
fn build_ui(&self) {
|
fn build_ui(&self) {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
@ -118,10 +121,12 @@ impl AddSubscriptionDialog {
|
|||||||
},
|
},
|
||||||
append: server_expander = &adw::ExpanderRow {
|
append: server_expander = &adw::ExpanderRow {
|
||||||
set_title: "Custom server...",
|
set_title: "Custom server...",
|
||||||
set_enable_expansion: false,
|
set_enable_expansion: imp.init_custom_server.get().is_some(),
|
||||||
|
set_expanded: imp.init_custom_server.get().is_some(),
|
||||||
set_show_enable_switch: true,
|
set_show_enable_switch: true,
|
||||||
add_row: server_entry = &adw::EntryRow {
|
add_row: server_entry = &adw::EntryRow {
|
||||||
set_title: "Server",
|
set_title: "Server",
|
||||||
|
set_text: imp.init_custom_server.get().map(|x| x.as_str()).unwrap_or(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -119,11 +119,12 @@ mod imp {
|
|||||||
impl NotifyWindow {
|
impl NotifyWindow {
|
||||||
#[template_callback]
|
#[template_callback]
|
||||||
fn show_add_topic(&self, _btn: >k::Button) {
|
fn show_add_topic(&self, _btn: >k::Button) {
|
||||||
let dialog = AddSubscriptionDialog::new();
|
let this = self.obj().clone();
|
||||||
|
let dialog =
|
||||||
|
AddSubscriptionDialog::new(this.selected_subscription().map(|x| x.server()));
|
||||||
dialog.set_transient_for(Some(&self.obj().clone()));
|
dialog.set_transient_for(Some(&self.obj().clone()));
|
||||||
dialog.present();
|
dialog.present();
|
||||||
|
|
||||||
let this = self.obj().clone();
|
|
||||||
let dc = dialog.clone();
|
let dc = dialog.clone();
|
||||||
dialog.connect_local("subscribe-request", true, move |_| {
|
dialog.connect_local("subscribe-request", true, move |_| {
|
||||||
let sub = match dc.subscription() {
|
let sub = match dc.subscription() {
|
||||||
|
|||||||
Reference in New Issue
Block a user