From ea78de7ffd20fc8ea7103eb469087923400723aa Mon Sep 17 00:00:00 2001 From: Colby Thomas Date: Wed, 27 Apr 2022 09:29:12 -0600 Subject: [PATCH] fix: remove tweet functionality if no browser available --- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- src/main.rs | 5 ++++- src/ui.rs | 7 ++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4cc60e0..f75c943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -811,7 +811,7 @@ dependencies = [ [[package]] name = "thokr" -version = "0.1.1" +version = "0.1.2" dependencies = [ "clap", "crossterm 0.23.2", @@ -1003,9 +1003,9 @@ dependencies = [ [[package]] name = "webbrowser" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9c28b6b6a78440b02647358625e3febc90724126480b9da6a967b5f674b3554" +checksum = "fc6a3cffdb686fbb24d9fb8f03a213803277ed2300f11026a3afe1f108dc021b" dependencies = [ "jni", "ndk-glue", diff --git a/Cargo.toml b/Cargo.toml index 236d1a5..6c442e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "thokr" description = "a sleek typing tui written in rust" -version = "0.1.1" +version = "0.1.2" readme = "README.md" repository = "https://github.com/coloradocolby/thokr.git" homepage = "https://github.com/coloradocolby/thokr" @@ -19,7 +19,7 @@ serde_json = "1.0.79" rand = "0.8.5" itertools = "0.10.3" unicode-width = "0.1.9" -webbrowser = "0.6.0" +webbrowser = "0.7.1" crossterm = "0.23.2" strum_macros = "0.24.0" include_dir = "0.7.2" diff --git a/src/main.rs b/src/main.rs index 27dbefb..1b78230 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ use tui::{ backend::{Backend, CrosstermBackend}, Frame, Terminal, }; +use webbrowser::Browser; /// a sleek typing tui written in rust #[derive(Parser, Debug, Clone)] @@ -182,8 +183,10 @@ fn start_tui( } true => match key.code { KeyCode::Char('t') => { - webbrowser::open(&format!("https://twitter.com/intent/tweet?text={}%20wpm%20%2F%20{}%25%20acc%20%2F%20{:.2}%20sd%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcoloradocolby%2Fthokr", app.thok.wpm, app.thok.accuracy, app.thok.std_dev)) + if Browser::is_available() { + webbrowser::open(&format!("https://twitter.com/intent/tweet?text={}%20wpm%20%2F%20{}%25%20acc%20%2F%20{:.2}%20sd%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcoloradocolby%2Fthokr", app.thok.wpm, app.thok.accuracy, app.thok.std_dev)) .unwrap_or_default(); + } } KeyCode::Char('r') => { exit_type = ExitType::Restart; diff --git a/src/ui.rs b/src/ui.rs index 523cbe1..f91c1c6 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -6,6 +6,7 @@ use tui::{ widgets::{Axis, Chart, Dataset, GraphType, Paragraph, Widget, Wrap}, }; use unicode_width::UnicodeWidthStr; +use webbrowser::Browser; use crate::thok::{Outcome, Thok}; @@ -184,7 +185,11 @@ impl Widget for &Thok { stats.render(chunks[1], buf); let legend = Paragraph::new(Span::styled( - String::from("(r)etry / (n)ew / (t)weet / (esc)ape"), + String::from(if Browser::is_available() { + "(r)etry / (n)ew / (t)weet / (esc)ape" + } else { + "(r)etry / (n)ew / (esc)ape" + }), italic_style, ));