Skip to content

Commit

Permalink
v2022.4.29 (#20)
Browse files Browse the repository at this point in the history
* Log out to stdout + file to make development a little easier (#17)

* Fixing startup crash with large limits (#18)

* Move up schema check/creation to right after we connect to db

* Gracefully handle invalid settings / lens files

* Add constraints to max inflight crawl/domain limits

* Wait for ipc connection longer

* Add notification crate

* apt-get update before install

* Fix cursor moving during selection + focus on show (#19)

* 🐛 Prevent cursor from moving around when user presses up/down when results are shown

* Force focus on search box when it pops into view

* Bumping versions for release 2022.4.29

* cargo fmt
  • Loading branch information
a5huynh authored Apr 30, 2022
1 parent 0963469 commit e708c16
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
run: rustup target add wasm32-unknown-unknown
- name: Install tauri system deps
run: |
sudo apt-get update -y
sudo apt-get install -y \
libwebkit2gtk-4.0-dev \
libgtk-3-dev \
Expand Down
45 changes: 28 additions & 17 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ serde_json = "1.0"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
wasm-logger = "0.2.0"
web-sys = "0.3"
web-sys = { version = "0.3", features = ["VisibilityState"] }
yew = "0.19.3"
53 changes: 48 additions & 5 deletions crates/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use gloo::events::EventListener;
use js_sys::Date;
use wasm_bindgen::prelude::*;
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen_futures::spawn_local;
use web_sys::{window, Element, HtmlInputElement};
use web_sys::{window, Element, HtmlElement, HtmlInputElement, VisibilityState};
use yew::prelude::*;

mod components;
Expand Down Expand Up @@ -72,6 +72,23 @@ pub fn app() -> Html {
});
|| drop(listener)
});

use_effect(move || {
// Attach a keydown event listener to the document.
let document = gloo::utils::document();
let listener = EventListener::new(&document.clone(), "visibilitychange", move |_| {
if document.visibility_state() == VisibilityState::Visible {
match document.get_element_by_id("searchbox") {
Some(el) => {
let el: HtmlElement = el.unchecked_into();
let _ = el.focus();
},
_ => {}
}
}
});
|| drop(listener)
});
}

// Handle changes to the query string
Expand Down Expand Up @@ -131,8 +148,32 @@ pub fn app() -> Html {
let onkeyup = {
let query = query.clone();
Callback::from(move |e: KeyboardEvent| {
let input: HtmlInputElement = e.target_unchecked_into();
query.set(input.value());
let key = e.key();
match key.as_str() {
"ArrowUp" => e.prevent_default(),
"ArrowDown" => e.prevent_default(),
_ => {
let input: HtmlInputElement = e.target_unchecked_into();
query.set(input.value());
}
}
})
};

let onkeydown = {
let search_results = search_results.clone();
Callback::from(move |e: KeyboardEvent| {
// No need to prevent default behavior if there are no search results.
if search_results.is_empty() {
return;
}

let key = e.key();
match key.as_str() {
"ArrowUp" => e.prevent_default(),
"ArrowDown" => e.prevent_default(),
_ => return,
}
})
};

Expand All @@ -141,13 +182,15 @@ pub fn app() -> Html {
<div class="query-container">
{selected_lens_list(&lens)}
<input
id={"searchbox"}
type={"text"}
class={"search-box"}
placeholder={"Search"}
value={(*query).clone()}
{onkeyup}
{onkeydown}
spellcheck={"false"}
tabindex={"0"}
tabindex={"-1"}
/>
</div>
<div class={"search-results-list"}>
Expand Down
68 changes: 53 additions & 15 deletions crates/shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use std::path::PathBuf;
use directories::ProjectDirs;
use serde::{Deserialize, Serialize};

pub const MAX_TOTAL_INFLIGHT: u32 = 100;
pub const MAX_DOMAIN_INFLIGHT: u32 = 100;

#[derive(Clone, Debug)]
pub struct Config {
pub user_settings: UserSettings,
Expand Down Expand Up @@ -72,6 +75,23 @@ impl UserSettings {
fn default_shortcut() -> String {
"CmdOrCtrl+Shift+/".to_string()
}

pub fn constraint_limits(&mut self) {
// Make sure crawler limits are reasonable
match self.inflight_crawl_limit {
Limit::Infinite => self.inflight_crawl_limit = Limit::Finite(MAX_TOTAL_INFLIGHT),
Limit::Finite(limit) => {
self.inflight_crawl_limit = Limit::Finite(limit.min(MAX_TOTAL_INFLIGHT))
}
}

match self.inflight_domain_limit {
Limit::Infinite => self.inflight_domain_limit = Limit::Finite(MAX_DOMAIN_INFLIGHT),
Limit::Finite(limit) => {
self.inflight_domain_limit = Limit::Finite(limit.min(MAX_DOMAIN_INFLIGHT))
}
}
}
}

impl Default for UserSettings {
Expand All @@ -92,20 +112,27 @@ impl Default for UserSettings {
}

impl Config {
fn load_user_settings() -> UserSettings {
fn load_user_settings() -> anyhow::Result<UserSettings> {
let prefs_path = Self::prefs_file();
if prefs_path.exists() {
ron::from_str(&fs::read_to_string(prefs_path).unwrap())
.expect("Unable to read user preferences file.")
} else {
let settings = UserSettings::default();
// Write out default settings
fs::write(
prefs_path,
ron::ser::to_string_pretty(&settings, Default::default()).unwrap(),
)
.expect("Unable to save user preferences file.");
settings

match prefs_path.exists() {
true => {
let mut settings: UserSettings =
ron::from_str(&fs::read_to_string(prefs_path).unwrap())?;
settings.constraint_limits();
Ok(settings)
}
_ => {
let settings = UserSettings::default();
// Write out default settings
fs::write(
prefs_path,
ron::ser::to_string_pretty(&settings, Default::default()).unwrap(),
)
.expect("Unable to save user preferences file.");

Ok(settings)
}
}
}

Expand Down Expand Up @@ -196,9 +223,20 @@ impl Config {
let lenses_dir = Config::lenses_dir();
fs::create_dir_all(&lenses_dir).expect("Unable to create `lenses` folder");

// Gracefully handle issues loading user settings/lenses
let user_settings = Self::load_user_settings().unwrap_or_else(|err| {
log::warn!("Invalid user settings file! Reason: {}", err);
Default::default()
});

let lenses = Self::load_lenses().unwrap_or_else(|err| {
log::warn!("Unable to load lenses! Reason: {}", err);
Default::default()
});

Config {
lenses: Self::load_lenses().expect("Unable to load lenses"),
user_settings: Self::load_user_settings(),
lenses,
user_settings,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/spyglass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tendril = "0.4.2"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-appender = "0.2"
tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3", features = ["env-filter", "std"]}
url = "2.2"
uuid = { version = "0.8", features = ["serde", "v4"], default-features = false }
Expand Down
21 changes: 12 additions & 9 deletions crates/spyglass/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::io;
use tokio::signal;
use tokio::sync::{broadcast, mpsc};
use tracing_subscriber::EnvFilter;
use tracing_log::LogTracer;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter};

use libspyglass::models::crawl_queue;
use libspyglass::state::AppState;
Expand All @@ -16,16 +18,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let file_appender = tracing_appender::rolling::daily(Config::logs_dir(), "server.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);

tracing_subscriber::fmt()
.with_thread_names(true)
.with_writer(non_blocking)
.with_env_filter(
EnvFilter::default()
let subscriber = tracing_subscriber::registry()
.with(
EnvFilter::from_default_env()
.add_directive(tracing::Level::INFO.into())
.add_directive("tantivy=WARN".parse().unwrap())
.add_directive("rocket=WARN".parse().unwrap()),
.add_directive("tantivy=WARN".parse().unwrap()),
)
.init();
.with(fmt::Layer::new().with_writer(io::stdout))
.with(fmt::Layer::new().with_ansi(false).with_writer(non_blocking));

tracing::subscriber::set_global_default(subscriber).expect("Unable to set a global subscriber");
LogTracer::init()?;

let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
Expand Down
Loading

0 comments on commit e708c16

Please sign in to comment.