Skip to content

Commit

Permalink
Linux bugfixes (#33)
Browse files Browse the repository at this point in the history
* Update tray menu on a regular basis

- Fixes an issue on linux where `SystemTrayEvent::Left/RightClick` 
is not supported.

* Move resume/pause crawler into crawler stats section

* Disable menu on linux (not needed for shortcuts to work unlike others)

* Reducing logging verbosity

* Fix input lag issue, debouncing wasn't implemented correctly nor required atm.

* cargo clippy
  • Loading branch information
a5huynh authored May 4, 2022
1 parent b68dba0 commit 01384b6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions crates/client/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#[allow(clippy::identity_op)]
pub const DEBOUNCE_TIME_MS: f64 = (1 * 1000) as f64;
pub const LENS_SEARCH_PREFIX: &str = "/";
pub const MIN_CHARS: usize = 2;
9 changes: 1 addition & 8 deletions crates/client/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use js_sys::Date;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::spawn_local;
Expand Down Expand Up @@ -71,16 +70,12 @@ pub fn handle_global_key_down(

pub fn handle_query_change(
query: &str,
query_debounce: UseStateHandle<f64>,
node_ref: UseStateHandle<NodeRef>,
lens: UseStateHandle<Vec<String>>,
search_results: UseStateHandle<Vec<ResultListData>>,
selected_idx: UseStateHandle<usize>,
) {
// Was the last char typed > 1 sec ago?
let is_debounced = *query_debounce >= constants::DEBOUNCE_TIME_MS;

if is_debounced && query.len() >= constants::MIN_CHARS {
if query.len() >= constants::MIN_CHARS {
let el = node_ref.cast::<Element>().unwrap();
if query.starts_with(constants::LENS_SEARCH_PREFIX) {
// show lens search
Expand All @@ -89,6 +84,4 @@ pub fn handle_query_change(
super::show_doc_results(search_results, &lens, el, selected_idx, query.to_string());
}
}

query_debounce.set(Date::now());
}
5 changes: 0 additions & 5 deletions crates/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use gloo::events::EventListener;
use js_sys::Date;
use wasm_bindgen::{prelude::*, JsCast};
use wasm_bindgen_futures::spawn_local;
use web_sys::{window, Element, HtmlElement, HtmlInputElement};
Expand Down Expand Up @@ -46,7 +45,6 @@ pub fn app() -> Html {
let lens = use_state_eq(Vec::new);
// Current query string
let query = use_state_eq(|| "".to_string());
let query_debounce = use_state_eq(Date::now);
// Search results + selected index
let search_results = use_state_eq(Vec::new);
let selected_idx = use_state_eq(|| 0);
Expand Down Expand Up @@ -87,7 +85,6 @@ pub fn app() -> Html {
move |query| {
events::handle_query_change(
query,
query_debounce,
node_ref,
lens,
search_results,
Expand Down Expand Up @@ -142,7 +139,6 @@ pub fn app() -> Html {
.collect::<Html>();

let onkeyup = {
let query = query.clone();
Callback::from(move |e: KeyboardEvent| {
let input: HtmlInputElement = e.target_unchecked_into();
query.set(input.value());
Expand Down Expand Up @@ -172,7 +168,6 @@ pub fn app() -> Html {
type={"text"}
class={"search-box"}
placeholder={"Search"}
value={(*query).clone()}
{onkeyup}
{onkeydown}
spellcheck={"false"}
Expand Down
2 changes: 1 addition & 1 deletion crates/spyglass/src/search/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn build_query(
.map(|token| token.trim())
.collect();

log::info!("lenses: {:?}, terms: {:?}", applied_lens, terms);
log::trace!("lenses: {:?}, terms: {:?}", applied_lens, terms);

let mut lense_queries: QueryVec = Vec::new();
for lens in applied_lens {
Expand Down
1 change: 1 addition & 0 deletions crates/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shared = { path = "../shared" }
tauri = { version = "1.0.0-rc.8", features = ["api-all", "ayatana-tray", "devtools", "notification", "system-tray"] }
tokio = "1"
tokio-retry = "0.3"
tracing = "0.1"
tracing-appender = "0.2"
Expand Down
33 changes: 22 additions & 11 deletions crates/tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use jsonrpc_core::Value;
use num_format::{Locale, ToFormattedString};
use std::io;
use std::path::PathBuf;
use std::time::Duration;

use jsonrpc_core::Value;
use num_format::{Locale, ToFormattedString};
use tauri::{AppHandle, GlobalShortcutManager, Manager, SystemTray, SystemTrayEvent};
use tokio::time;
use tracing_log::LogTracer;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter};

Expand Down Expand Up @@ -53,12 +56,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory);

let window = app.get_window("main").unwrap();

// Start up backend (only in release mode)
#[cfg(not(debug_assertions))]
rpc::check_and_start_backend();

let window = app.get_window("main").unwrap();
let _ = window.set_skip_taskbar(true);

// Wait for the server to boot up
app.manage(tauri::async_runtime::block_on(rpc::RpcClient::new()));

Expand Down Expand Up @@ -87,6 +91,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Center window horizontally in the current screen
window::center_window(&window);

// Keep system tray stats updated
let app_handle = app.app_handle();
tauri::async_runtime::spawn(async move {
let mut interval = time::interval(Duration::from_secs(10));
loop {
update_tray_menu(&app_handle).await;
interval.tick().await;
}
});

Ok(())
})
.on_window_event(|event| {
Expand All @@ -97,10 +111,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
})
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::LeftClick { .. } => update_tray_menu(app),
SystemTrayEvent::RightClick { .. } => update_tray_menu(app),
SystemTrayEvent::MenuItemClick { id, .. } => {
.on_system_tray_event(|app, event| {
if let SystemTrayEvent::MenuItemClick { id, .. } = event {
let item_handle = app.tray_handle().get_item(&id);
let window = app.get_window("main").unwrap();

Expand Down Expand Up @@ -130,7 +142,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
_ => {}
}
}
_ => {}
})
.run(ctx)
.expect("error while running tauri application");
Expand Down Expand Up @@ -186,10 +197,10 @@ fn open_folder(folder: PathBuf) {
.unwrap();
}

fn update_tray_menu(app: &AppHandle) {
async fn update_tray_menu(app: &AppHandle) {
let rpc = app.state::<rpc::RpcClient>().inner();

let app_status = tauri::async_runtime::block_on(app_status(rpc));
let app_status = app_status(rpc).await;
let handle = app.tray_handle();

if let Some(app_status) = app_status {
Expand Down
6 changes: 5 additions & 1 deletion crates/tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub fn get_tray_menu(config: &Config) -> SystemTrayMenu {

let mut tray = SystemTrayMenu::new();
tray = tray
.add_item(pause)
.add_item(show)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(
Expand All @@ -42,6 +41,7 @@ pub fn get_tray_menu(config: &Config) -> SystemTrayMenu {
CustomMenuItem::new(NUM_DOCS_MENU_ITEM.to_string(), "XX documents indexed").disabled(),
)
.add_item(CustomMenuItem::new(NUM_QUEUED_MENU_ITEM.to_string(), "XX queued").disabled())
.add_item(pause)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(open_lenses_folder)
.add_item(open_settings_folder)
Expand All @@ -59,6 +59,10 @@ pub fn get_tray_menu(config: &Config) -> SystemTrayMenu {
}

pub fn get_app_menu() -> Menu {
if cfg!(target_os = "linux") {
return Menu::new();
}

let ctx = tauri::generate_context!();

Menu::new().add_submenu(Submenu::new(
Expand Down

0 comments on commit 01384b6

Please sign in to comment.