Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queue url confirmation dialog #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/core/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ pub enum Event {
Back,
Quit,
WakeUp,
QueueAddUrl(String),
}

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
36 changes: 23 additions & 13 deletions crates/core/src/view/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use self::bottom_bar::BottomBar;
use self::results_bar::ResultsBar;
use crate::view::common::{locate, rlocate, locate_by_id};
use crate::view::common::{toggle_main_menu, toggle_battery_menu, toggle_clock_menu};
use crate::view::dialog::Dialog;
use crate::view::filler::Filler;
use crate::view::named_input::NamedInput;
use crate::view::search_bar::SearchBar;
Expand Down Expand Up @@ -3135,19 +3136,12 @@ impl View for Reader {
hub.send(Event::GoTo(location)).ok();
} else {
if link.text.starts_with("https:") || link.text.starts_with("http:") {
if let Some(path) = context.settings.external_urls_queue.as_ref() {
if let Ok(mut file) = OpenOptions::new().create(true)
.append(true)
.open(path) {
if let Err(e) = writeln!(file, "{}", link.text) {
eprintln!("Couldn't write to {}: {:#}.", path.display(), e);
} else {
let message = format!("Queued {}.", link.text);
let notif = Notification::new(message, hub, rq, context);
self.children.push(Box::new(notif) as Box<dyn View>);
}
}
}
let dialog = Dialog::new(ViewId::ShareDialog,
Some(Event::QueueAddUrl(link.text)),
"Add url to queue?".to_string(),
context);
rq.add(RenderData::new(dialog.id(), *dialog.rect(), UpdateMode::Gui));
self.children.push(Box::new(dialog) as Box<dyn View>);
} else {
eprintln!("Can't resolve URI: {}.", link.text);
}
Expand Down Expand Up @@ -3267,6 +3261,22 @@ impl View for Reader {

true
},
Event::QueueAddUrl(ref link) => {
if let Some(path) = context.settings.external_urls_queue.as_ref() {
if let Ok(mut file) = OpenOptions::new().create(true)
.append(true)
.open(path) {
if let Err(e) = writeln!(file, "{}", link) {
eprintln!("Couldn't write to {}: {:#}.", path.display(), e);
} else {
let message = format!("Queued {}.", link);
let notif = Notification::new(message, hub, rq, context);
self.children.push(Box::new(notif) as Box<dyn View>);
}
}
}
true
}
Event::Gesture(GestureEvent::HoldFingerShort(center, id)) if self.rect.includes(center) => {
if self.focus.is_some() {
return true;
Expand Down