Skip to content

Commit

Permalink
launch GUI if not tty and turn keys green when their corresponding le…
Browse files Browse the repository at this point in the history
…tters are typed
  • Loading branch information
TabulateJarl8 committed Feb 21, 2022
1 parent e9d7544 commit 7a786e5
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 64 deletions.
93 changes: 47 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "wordle_finder"
version = "2.1.0"
version = "2.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atty = "0.2.14"
clap = "3.0.14"
regex = "1.5.4"
serde = { version = "1.0.136", features = ["derive"] }
Expand Down
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{Arg, App};
use clap::{Arg, Command};
use regex::Regex;
use serde::Deserialize;
use std::{
Expand All @@ -10,11 +10,13 @@ use wry::{
webview::WebView,
};

// TODO: Bundle WebView2Loader.dll for windows users

thread_local! {
static WEBVIEWS: RefCell<HashMap<WindowId, WebView>> = RefCell::new(HashMap::new());
}

static VERSION: &str = "2.1.0";
static VERSION: &str = "2.2.0";

fn remove_whitespace(s: &str) -> String {
s.chars().filter(|c| !c.is_whitespace()).collect()
Expand All @@ -32,7 +34,7 @@ fn contains_all(word: &str, characters: &str) -> bool {

fn main() {
// clap setup
let matches = App::new("Wordle Finder")
let matches = Command::new("Wordle Finder")
.version(VERSION)
.author("Connor Sample (TabulateJarl8)")
.about("Helper tool to narrow down choices for wordle word")
Expand Down Expand Up @@ -62,8 +64,8 @@ fn main() {
.required(false))
.get_matches();

// run gui if specified
if matches.is_present("gui") {
// run gui if specified or if not a tty (not running from a terminal)
if matches.is_present("gui") || !atty::is(atty::Stream::Stdout) {
match run_gui() {
Err(error) => panic!("Error when running GUI: {:?}", error),
_ => (),
Expand Down Expand Up @@ -117,7 +119,7 @@ fn run_gui() -> wry::Result<()> {
// add webview and window ID to WEBVIEWS refcell hashmap
let mut webview_hashmap: HashMap<WindowId, WebView> = HashMap::new();
webview_hashmap.insert(window_id, webview);
// RefCell<HashMap<WindowId, WebView>> = RefCell::new(HashMap::new());

WEBVIEWS.with(|webviews| {
*webviews.borrow_mut() = webview_hashmap;
});
Expand Down
Loading

0 comments on commit 7a786e5

Please sign in to comment.