Skip to content

Commit 1e34f4e

Browse files
committed
fmt
1 parent 3ddb669 commit 1e34f4e

File tree

6 files changed

+42
-50
lines changed

6 files changed

+42
-50
lines changed

src/common/mod.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ use url::Url;
99

1010
use crate::gemini;
1111

12-
pub static DOWNLOAD_PATH: Lazy<std::path::PathBuf> =
13-
Lazy::new(|| {
14-
let mut download_path = glib::user_special_dir(glib::UserDirectory::Downloads)
15-
.expect("Can't access download directory");
16-
download_path.push("Geopard");
17-
if !download_path.exists() {
18-
std::fs::create_dir(&download_path).expect("Can't create download folder");
19-
}
20-
download_path
21-
});
12+
pub static DOWNLOAD_PATH: Lazy<std::path::PathBuf> = Lazy::new(|| {
13+
let mut download_path = glib::user_special_dir(glib::UserDirectory::Downloads)
14+
.expect("Can't access download directory");
15+
download_path.push("Geopard");
16+
if !download_path.exists() {
17+
std::fs::create_dir(&download_path).expect("Can't create download folder");
18+
}
19+
download_path
20+
});
2221

2322
pub static ABOUT_PAGE: &str = std::include_str!("../../README.gemini");
2423

@@ -52,16 +51,7 @@ should remove bookmarks.
5251
## Custom bookmarks:
5352
";
5453

55-
pub const STREAMABLE_EXTS: [&str; 8] = [
56-
"mp3",
57-
"mp4",
58-
"webm",
59-
"opus",
60-
"wav",
61-
"ogg",
62-
"mkv",
63-
"flac",
64-
];
54+
pub const STREAMABLE_EXTS: [&str; 8] = ["mp3", "mp4", "webm", "opus", "wav", "ogg", "mkv", "flac"];
6555

6656
pub fn bookmarks_url() -> Url {
6757
Url::parse(&format!("file://{}", BOOKMARK_FILE_PATH.to_str().unwrap())).unwrap()

src/download_page.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use glib::subclass::prelude::*;
12
use gtk::glib;
23
use gtk::prelude::*;
34
use gtk::subclass::prelude::*;
4-
use glib::subclass::prelude::*;
55
use gtk::CompositeTemplate;
66
use gtk::TemplateChild;
77

@@ -16,11 +16,10 @@ mod imp {
1616
pub label_downloaded: TemplateChild<gtk::Label>,
1717
#[template_child]
1818
pub progress_bar: TemplateChild<gtk::ProgressBar>,
19-
#[template_child]
19+
#[template_child]
2020
pub open_btn: TemplateChild<gtk::Button>,
2121
}
2222

23-
2423
#[glib::object_subclass]
2524
impl ObjectSubclass for DownloadPage {
2625
// `NAME` needs to match `class` attribute of template

src/input_page.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use glib::subclass::prelude::*;
12
use gtk::glib;
23
use gtk::prelude::*;
34
use gtk::subclass::prelude::*;
4-
use glib::subclass::prelude::*;
55
use gtk::CompositeTemplate;
66
use gtk::TemplateChild;
77

@@ -12,11 +12,10 @@ mod imp {
1212
pub struct InputPage {
1313
#[template_child]
1414
pub label: TemplateChild<gtk::Label>,
15-
#[template_child]
15+
#[template_child]
1616
pub entry: TemplateChild<gtk::Entry>,
1717
}
1818

19-
2019
#[glib::object_subclass]
2120
impl ObjectSubclass for InputPage {
2221
// `NAME` needs to match `class` attribute of template

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ use gtk::gio;
99
use std::cell::RefCell;
1010
use std::rc::Rc;
1111

12+
mod build_config;
1213
mod common;
1314
mod config;
14-
mod build_config;
15+
mod download_page;
1516
mod draw_ctx;
1617
mod gemini;
18+
mod input_page;
1719
mod macros;
1820
mod tab;
1921
mod window;
20-
mod input_page;
21-
mod download_page;
2222

2323
use gtk::prelude::*;
2424

src/tab.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use gtk::gio;
1010
use gtk::glib;
1111
use gtk::prelude::*;
1212
use gtk::subclass::prelude::*;
13+
use gtk::CompositeTemplate;
14+
use gtk::TemplateChild;
1315
use log::{debug, error, info};
1416
use once_cell::sync::Lazy;
1517
use std::cell::RefCell;
1618
use std::marker::PhantomData;
1719
use std::pin::Pin;
1820
use std::rc::Rc;
1921
use url::Url;
20-
use gtk::CompositeTemplate;
21-
use gtk::TemplateChild;
2222

2323
use crate::common;
2424
use crate::common::{glibctx, HistoryItem, LossyTextRead, PageElement, RequestCtx};
@@ -42,7 +42,7 @@ pub mod imp {
4242
pub(crate) draw_ctx: RefCell<Option<DrawCtx>>,
4343
pub(crate) history: RefCell<Vec<HistoryItem>>,
4444
pub(crate) current_hi: RefCell<Option<usize>>,
45-
#[template_child]
45+
#[template_child]
4646
pub(crate) scroll_win: TemplateChild<gtk::ScrolledWindow>,
4747
#[template_child]
4848
pub(crate) text_view: TemplateChild<gtk::TextView>,
@@ -142,11 +142,15 @@ impl Tab {
142142
pub fn new(config: crate::config::Config) -> Self {
143143
let this: Self = glib::Object::new(&[]).unwrap();
144144
let imp = this.imp();
145-
imp.text_view.add_controller(imp.left_click_ctrl.borrow().as_ref().unwrap());
146-
imp.text_view.add_controller(imp.right_click_ctrl.borrow().as_ref().unwrap());
147-
imp.text_view.add_controller(imp.motion_ctrl.borrow().as_ref().unwrap());
145+
imp.text_view
146+
.add_controller(imp.left_click_ctrl.borrow().as_ref().unwrap());
147+
imp.text_view
148+
.add_controller(imp.right_click_ctrl.borrow().as_ref().unwrap());
149+
imp.text_view
150+
.add_controller(imp.motion_ctrl.borrow().as_ref().unwrap());
148151

149-
imp.draw_ctx.replace(Some(DrawCtx::new(imp.text_view.clone(), config)));
152+
imp.draw_ctx
153+
.replace(Some(DrawCtx::new(imp.text_view.clone(), config)));
150154

151155
this.bind_signals();
152156
this
@@ -212,7 +216,6 @@ impl Tab {
212216
pub fn spawn_open_url(&self, url: Url) {
213217
let imp = self.imp();
214218

215-
216219
let i = self.add_to_history(HistoryItem {
217220
url: url.clone(),
218221
cache: Default::default(),
@@ -253,7 +256,7 @@ impl Tab {
253256
imp.stack.set_visible_child(&first_page.child());
254257
for page in iter.skip(1) {
255258
imp.stack.remove(&page.unwrap().child());
256-
};
259+
}
257260
}
258261
fn spawn_request(&self, fut: impl Future<Output = ()> + 'static) {
259262
let imp = self.imp();
@@ -543,7 +546,6 @@ impl Tab {
543546
gtk::show_uri(None::<&gtk::Window>, &downloaded_file_url, 0);
544547
});
545548

546-
547549
let ext = file_name.split(".").last();
548550
if let Some(true) = ext.map(|ext| crate::common::STREAMABLE_EXTS.contains(&ext)) {
549551
page.imp().open_btn.set_opacity(1.0);
@@ -567,7 +569,9 @@ impl Tab {
567569
let t = glib::real_time();
568570
if t - last_update_time > THROTTLE_TIME {
569571
page.imp().progress_bar.pulse();
570-
page.imp().label_downloaded.set_text(&format!("{:.2}KB", read as f64 / 1000.0));
572+
page.imp()
573+
.label_downloaded
574+
.set_text(&format!("{:.2}KB", read as f64 / 1000.0));
571575
last_update_time = t;
572576
}
573577
}
@@ -577,7 +581,9 @@ impl Tab {
577581
Err(e) => return Err(e.into()),
578582
}
579583
}
580-
page.imp().label_downloaded.set_text(&format!("{:.2}KB", read as f64 / 1000.0));
584+
page.imp()
585+
.label_downloaded
586+
.set_text(&format!("{:.2}KB", read as f64 / 1000.0));
581587
page.imp().progress_bar.set_fraction(1.0);
582588
page.imp().open_btn.set_opacity(1.0);
583589
page.imp().open_btn.set_label("Open");
@@ -617,7 +623,6 @@ impl Tab {
617623
.activate_action("win.open-url", Some(&url.to_string().to_variant()))
618624
.unwrap();
619625
});
620-
621626
}
622627

623628
fn display_url_confirmation(ctx: &mut DrawCtx, url: &Url) {

src/window.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,13 @@ impl Window {
359359
});
360360
}
361361
fn open_omni(&self, v: &str) {
362-
let url = Url::parse(v)
363-
.or_else(|_| {
364-
if v.contains(".") && v.split(".").all(|s| s.chars().all(char::is_alphanumeric)) {
365-
Url::parse(&format!("gemini://{}", v))
366-
} else {
367-
Url::parse(&format!("gemini://geminispace.info/search?{}", v))
368-
}
369-
});
362+
let url = Url::parse(v).or_else(|_| {
363+
if v.contains(".") && v.split(".").all(|s| s.chars().all(char::is_alphanumeric)) {
364+
Url::parse(&format!("gemini://{}", v))
365+
} else {
366+
Url::parse(&format!("gemini://geminispace.info/search?{}", v))
367+
}
368+
});
370369
match url {
371370
Ok(url) => self.current_tab().spawn_open_url(url),
372371
Err(e) => error!("Failed to open from omni bar"),

0 commit comments

Comments
 (0)