2026-08-02 19:04:30 -04:00
|
|
|
//! QuickSearch binary: `quicksearch <query>` searches from the terminal;
|
|
|
|
|
//! without a query it opens the egui desktop app.
|
|
|
|
|
//!
|
|
|
|
|
//! On Windows this is the GUI only, built as a window-subsystem app so no
|
|
|
|
|
//! console flashes behind it. Terminal search there is `quicksearch-cli`,
|
|
|
|
|
//! which is a console app and so keeps working pipes, exit codes, and a shell
|
|
|
|
|
//! that waits for it. A query passed here still does something useful: it
|
|
|
|
|
//! seeds the search box.
|
|
|
|
|
#![cfg_attr(windows, windows_subsystem = "windows")]
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
mod app;
|
|
|
|
|
mod backend;
|
2026-08-04 23:33:28 -04:00
|
|
|
#[cfg(feature = "capture")]
|
|
|
|
|
mod capture;
|
2026-08-02 19:04:30 -04:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
|
mod cli;
|
2026-08-09 02:58:13 -04:00
|
|
|
mod color;
|
2026-08-02 19:04:30 -04:00
|
|
|
mod duplicates_tab;
|
|
|
|
|
mod format;
|
2026-08-02 20:21:19 -04:00
|
|
|
mod help_tab;
|
2026-08-09 02:58:13 -04:00
|
|
|
mod hotkey;
|
2026-08-02 20:21:19 -04:00
|
|
|
mod keychain;
|
2026-08-02 19:04:30 -04:00
|
|
|
mod logs_tab;
|
|
|
|
|
mod manage_tab;
|
|
|
|
|
mod platform;
|
|
|
|
|
mod query_highlight;
|
|
|
|
|
mod search_tab;
|
2026-08-17 19:26:18 -04:00
|
|
|
mod settings_tab;
|
2026-08-05 18:05:04 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod test_ui;
|
|
|
|
|
mod tips;
|
2026-08-02 19:04:30 -04:00
|
|
|
mod tracker;
|
2026-08-17 19:26:18 -04:00
|
|
|
mod tutorial;
|
2026-08-02 20:21:19 -04:00
|
|
|
mod ui_util;
|
2026-08-02 22:21:39 -04:00
|
|
|
mod unlock;
|
2026-08-04 23:33:28 -04:00
|
|
|
mod version;
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
use quicksearch_core::config::Config;
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
/// The window icon, shown in the titlebar, taskbar and alt-tab switcher.
|
|
|
|
|
///
|
|
|
|
|
/// X11 takes these pixels directly via `_NET_WM_ICON`. Wayland ignores them and
|
|
|
|
|
/// instead looks up the app id in `/usr/share/applications/`, so the id below has
|
|
|
|
|
/// to match the installed `quicksearch.desktop` for the icon to appear there.
|
|
|
|
|
fn app_icon() -> egui::IconData {
|
|
|
|
|
eframe::icon_data::from_png_bytes(include_bytes!("../assets/icons/quicksearch-256.png"))
|
|
|
|
|
.expect("bundled icon is a valid PNG")
|
|
|
|
|
}
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
/// Leftover positional arguments, joined — used to seed the search box.
|
2026-08-09 16:25:43 -04:00
|
|
|
/// Flags are dropped rather than parsed: eframe and winit take some of
|
|
|
|
|
/// their own.
|
2026-08-02 19:04:30 -04:00
|
|
|
fn seed_query() -> Option<String> {
|
|
|
|
|
let terms: Vec<String> = std::env::args()
|
|
|
|
|
.skip(1)
|
|
|
|
|
.filter(|a| !a.starts_with('-'))
|
|
|
|
|
.collect();
|
|
|
|
|
if terms.is_empty() {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
Some(terms.join(" "))
|
|
|
|
|
}
|
2026-04-21 23:00:47 -04:00
|
|
|
}
|
|
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
fn main() {
|
|
|
|
|
// Must come first: anything below may print, and printing without a
|
|
|
|
|
// stdio handle panics rather than failing quietly.
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
platform::redirect_null_stdio();
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
|
if let Some(code) = cli::maybe_run_cli() {
|
|
|
|
|
std::process::exit(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A broken config file should never keep the window from opening —
|
|
|
|
|
// surface the error in-app and run on defaults.
|
|
|
|
|
let (config, config_error) = match Config::load() {
|
|
|
|
|
Ok(c) => (c, None),
|
|
|
|
|
Err(e) => (Config::default(), Some(e)),
|
2026-04-21 23:00:47 -04:00
|
|
|
};
|
2026-08-02 19:04:30 -04:00
|
|
|
let initial_query = seed_query();
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 20:21:19 -04:00
|
|
|
// With protection on, try the keychain before the window opens; a
|
2026-08-09 16:25:43 -04:00
|
|
|
// verified key means no prompt at all. `None` starts locked, and no
|
|
|
|
|
// index is touched until unlocked.
|
2026-08-03 03:06:19 -04:00
|
|
|
let key_source = if !config.security.password_protected {
|
|
|
|
|
Some(unlock::KeySource::Unprotected)
|
|
|
|
|
} else if unlock::try_keychain_unlock(&config) {
|
|
|
|
|
Some(unlock::KeySource::Keychain)
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
};
|
2026-08-02 20:21:19 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
let native_options = eframe::NativeOptions {
|
|
|
|
|
viewport: egui::ViewportBuilder::default()
|
|
|
|
|
.with_title("QuickSearch")
|
|
|
|
|
.with_app_id("quicksearch")
|
|
|
|
|
.with_icon(app_icon())
|
|
|
|
|
.with_inner_size([1000.0, 700.0])
|
|
|
|
|
.with_min_inner_size([640.0, 400.0]),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
2026-04-21 23:00:47 -04:00
|
|
|
|
2026-08-02 19:04:30 -04:00
|
|
|
let result = eframe::run_native(
|
|
|
|
|
"QuickSearch",
|
|
|
|
|
native_options,
|
|
|
|
|
Box::new(move |cc| {
|
2026-08-09 16:25:43 -04:00
|
|
|
// On Windows the registration owns a hidden window whose messages
|
|
|
|
|
// the event loop must dispatch, so it must be made on that loop's
|
|
|
|
|
// thread with the loop running — this closure is the first place
|
|
|
|
|
// that is true. Before the gate, so the shortcut works while the
|
|
|
|
|
// unlock screen is up.
|
2026-08-09 02:58:13 -04:00
|
|
|
hotkey::init(&cc.egui_ctx, &config.ui.search_hotkey);
|
2026-08-09 16:25:43 -04:00
|
|
|
// Before the gate so the unlock screen honors the setting.
|
2026-08-09 02:58:13 -04:00
|
|
|
app::apply_theme(&cc.egui_ctx, &config.ui.color_scheme);
|
2026-08-03 03:06:19 -04:00
|
|
|
let gate = match key_source {
|
|
|
|
|
Some(source) => {
|
|
|
|
|
unlock::Gate::running(&cc.egui_ctx, config, config_error, initial_query, source)
|
|
|
|
|
.map_err(Box::<dyn std::error::Error + Send + Sync>::from)?
|
|
|
|
|
}
|
|
|
|
|
None => unlock::Gate::locked(config, config_error, initial_query),
|
2026-08-02 20:21:19 -04:00
|
|
|
};
|
|
|
|
|
Ok(Box::new(gate) as Box<dyn eframe::App>)
|
2026-08-02 19:04:30 -04:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
if let Err(e) = result {
|
|
|
|
|
eprintln!("failed to start GUI: {}", e);
|
|
|
|
|
std::process::exit(1);
|
2026-04-21 23:00:47 -04:00
|
|
|
}
|
|
|
|
|
}
|