diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 71c0ca3..7d57942 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,9 +4,6 @@ on: push: tags: ["v*"] -permissions: - contents: write - env: DL_DIR: /srv/breadway-dl ECOSYSTEM_DIR: /home/breadway/Projects/bread-ecosystem @@ -17,8 +14,8 @@ jobs: steps: - uses: actions/checkout@v4 - - name: install build deps - run: sudo apt-get install -y libgtk-4-dev librsvg2-dev libdbus-1-dev pkg-config 2>/dev/null || true + - name: install system deps + run: sudo pacman -S --noconfirm gtk4 gtk4-layer-shell librsvg 2>/dev/null || true - name: build run: cargo build --release --locked @@ -37,7 +34,7 @@ jobs: cp packaging/breadbox-sync.service "${PKG_DIR}/" cp config.example.toml "${PKG_DIR}/" cp bakery.toml "${PKG_DIR}/bakery.toml" - ln -sfn "${VERSION}" "${DL_DIR}/breadbox/latest" + ln -sfn "${PKG_DIR}" "${DL_DIR}/breadbox/latest" - name: ensure bread-ecosystem run: | @@ -57,8 +54,6 @@ jobs: run: | VERSION="${GITHUB_REF_NAME#v}" PKG_DIR="${DL_DIR}/breadbox/${VERSION}" - gh release create "${GITHUB_REF_NAME}" \ - --title "breadbox v${VERSION}" --generate-notes 2>/dev/null || true gh release upload "${GITHUB_REF_NAME}" \ "${PKG_DIR}/breadbox-x86_64" \ "${PKG_DIR}/breadbox-sync-x86_64" \ diff --git a/Cargo.lock b/Cargo.lock index 77c0113..d72548f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,14 +22,13 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.13.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "bread-theme" version = "0.1.0" -source = "git+https://github.com/Breadway/bread-ecosystem?tag=v0.1.0#6b5f4f475f66a645b08cb865e6dda8228d23679b" dependencies = [ "dirs", "gtk4", @@ -39,7 +38,7 @@ dependencies = [ [[package]] name = "breadbox" -version = "0.2.1" +version = "0.1.0" dependencies = [ "bread-theme", "breadbox-shared", @@ -50,16 +49,15 @@ dependencies = [ [[package]] name = "breadbox-shared" -version = "0.2.1" +version = "0.1.0" dependencies = [ "serde", - "serde_json", "toml 0.8.23", ] [[package]] name = "breadbox-sync" -version = "0.2.1" +version = "0.1.0" dependencies = [ "breadbox-shared", "serde_json", @@ -91,9 +89,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.63" +version = "1.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" dependencies = [ "find-msvc-tools", "shlex", @@ -101,9 +99,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.20.8" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb693542bcafa528e198be0ebd9d3632ca5b7c93dbe7237460e199910835997c" +checksum = "3c6b04e07d8080154ed4ac03546d9a2b303cc2fe1901ba0b35b301516e289368" dependencies = [ "smallvec", "target-lexicon", @@ -147,9 +145,9 @@ dependencies = [ [[package]] name = "displaydoc" -version = "0.2.6" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", @@ -726,15 +724,15 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "log" -version = "0.4.32" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "memchr" -version = "2.8.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "memoffset" @@ -824,7 +822,7 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" dependencies = [ - "toml_edit 0.25.12+spec-1.1.0", + "toml_edit 0.25.11+spec-1.1.0", ] [[package]] @@ -983,9 +981,9 @@ dependencies = [ [[package]] name = "shlex" -version = "2.0.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simd-adler32" @@ -1054,9 +1052,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.13.5" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" +checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" [[package]] name = "thiserror" @@ -1149,9 +1147,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.25.12+spec-1.1.0" +version = "0.25.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2153edc6955a6c354fad8f5efd38b6a8769bdccf9fe50f8e1329f81b0baa5d7" +checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b" dependencies = [ "indexmap", "toml_datetime 1.1.1+spec-1.1.0", @@ -1442,9 +1440,9 @@ checksum = "3ae8337f8a065cfc972643663ea4279e04e7256de865aa66fe25cec5fb912d3f" [[package]] name = "yoke" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" dependencies = [ "stable_deref_trait", "yoke-derive", diff --git a/bakery.toml b/bakery.toml index f2abae4..1f16c1f 100644 --- a/bakery.toml +++ b/bakery.toml @@ -2,7 +2,6 @@ name = "breadbox" description = "App launcher for Hyprland / Wayland" binaries = ["breadbox", "breadbox-sync"] system_deps = ["gtk4", "gtk4-layer-shell", "librsvg"] -optional_system_deps = ["hyprland"] bread_deps = [] [[service]] diff --git a/breadbox-shared/Cargo.toml b/breadbox-shared/Cargo.toml index a47dc19..1600acd 100644 --- a/breadbox-shared/Cargo.toml +++ b/breadbox-shared/Cargo.toml @@ -1,10 +1,9 @@ [package] name = "breadbox-shared" -version = "0.2.1" +version = "0.1.0" edition = "2021" license = "MIT" [dependencies] serde = { version = "1", features = ["derive"] } -serde_json = "1" toml = "0.8" diff --git a/breadbox-shared/src/lib.rs b/breadbox-shared/src/lib.rs index 5286729..8ce6f7d 100644 --- a/breadbox-shared/src/lib.rs +++ b/breadbox-shared/src/lib.rs @@ -1,5 +1,4 @@ use std::{ - collections::HashMap, env, fs::{self, File}, io::{BufRead, BufReader}, @@ -216,38 +215,6 @@ impl Default for IconCache { } } -// ---- Launch history --------------------------------------------------------- - -pub struct LaunchHistory { - counts: HashMap, - path: PathBuf, -} - -impl LaunchHistory { - pub fn load() -> Self { - let path = cache_dir().join("history.json"); - let counts = fs::read_to_string(&path) - .ok() - .and_then(|s| serde_json::from_str(&s).ok()) - .unwrap_or_default(); - LaunchHistory { counts, path } - } - - pub fn count(&self, name: &str) -> u32 { - self.counts.get(name).copied().unwrap_or(0) - } - - pub fn increment(&mut self, name: &str) { - *self.counts.entry(name.to_string()).or_insert(0) += 1; - } - - pub fn save(&self) { - if let Ok(json) = serde_json::to_string(&self.counts) { - let _ = fs::write(&self.path, json); - } - } -} - // ---- Config ----------------------------------------------------------------- #[derive(Debug, Clone, Serialize, Deserialize, Default)] diff --git a/breadbox-sync/Cargo.toml b/breadbox-sync/Cargo.toml index 93b7392..1c68856 100644 --- a/breadbox-sync/Cargo.toml +++ b/breadbox-sync/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "breadbox-sync" -version = "0.2.1" +version = "0.1.0" edition = "2021" license = "MIT" diff --git a/breadbox/Cargo.toml b/breadbox/Cargo.toml index 1de3b4e..47ca6ee 100644 --- a/breadbox/Cargo.toml +++ b/breadbox/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "breadbox" -version = "0.2.1" +version = "0.1.0" edition = "2021" license = "MIT" @@ -9,7 +9,9 @@ name = "breadbox" path = "src/main.rs" [dependencies] -bread-theme = { git = "https://github.com/Breadway/bread-ecosystem", tag = "v0.1.0", features = ["gtk"] } +# Path dep for local dev; replace with git dep on first tag: +# bread-theme = { git = "https://github.com/Breadway/bread-ecosystem", tag = "theme-v0.1.0", features = ["gtk"] } +bread-theme = { path = "../../bread-ecosystem/bread-theme", features = ["gtk"] } breadbox-shared = { path = "../breadbox-shared" } gtk4 = { version = "0.11", features = ["v4_12"] } gtk4-layer-shell = "0.8" diff --git a/breadbox/src/main.rs b/breadbox/src/main.rs index 0fbab50..29338a9 100644 --- a/breadbox/src/main.rs +++ b/breadbox/src/main.rs @@ -1,6 +1,5 @@ use bread_theme::{hex_to_rgba, load_palette, Palette}; use std::{ - cell::RefCell, collections::HashMap, env, fs, @@ -12,7 +11,7 @@ use std::{ }; use breadbox_shared::{ - config_dir, load_all_desktop_entries, Config, DesktopEntry, IconCache, LaunchHistory, + config_dir, load_all_desktop_entries, Config, DesktopEntry, IconCache, }; use gtk4::{ gdk::Display, @@ -59,7 +58,6 @@ fn load_manifest() -> HashMap { fn load_sorted_entries( manifest: &HashMap, priority: &[String], - history: &LaunchHistory, ) -> Vec { let mut entries = load_all_desktop_entries(); @@ -81,11 +79,7 @@ fn load_sorted_entries( (Some(i), Some(j)) => i.cmp(&j), (Some(_), None) => std::cmp::Ordering::Less, (None, Some(_)) => std::cmp::Ordering::Greater, - (None, None) => { - // Most-launched first, then alphabetical - history.count(&b.name).cmp(&history.count(&a.name)) - .then(a.name.to_lowercase().cmp(&b.name.to_lowercase())) - } + (None, None) => a.name.to_lowercase().cmp(&b.name.to_lowercase()), } }); @@ -236,17 +230,6 @@ fn fuzzy_matches(pattern: &str, text: &str) -> bool { true } -fn fuzzy_score(query: &str, entry: &DesktopEntry) -> u32 { - let q = query.to_lowercase(); - let name = entry.name.to_lowercase(); - let wm = entry.wm_class.as_deref().unwrap_or("").to_lowercase(); - if name == q || wm == q { return 0; } - if name.starts_with(&q) { return 1; } - if name.contains(&q) { return 2; } - if wm.starts_with(&q) || wm.contains(&q) { return 3; } - 4 // subsequence match -} - // ---- PID file toggle -------------------------------------------------------- fn pid_file() -> PathBuf { @@ -290,14 +273,11 @@ fn get_row_entry(row: >k4::ListBoxRow) -> Option { } } -fn run_ui(entries: Vec, css: String, history: LaunchHistory) { +fn run_ui(entries: Vec, css: String) { let app = Application::builder() .application_id("com.breadway.breadbox") .build(); - let history_rc = Rc::new(RefCell::new(history)); - let query_rc: Rc> = Rc::new(RefCell::new(String::new())); - app.connect_activate(move |app| { // Base CSS let provider = CssProvider::new(); @@ -310,6 +290,7 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { // User CSS override { + use std::cell::RefCell; let user_css_path = config_dir().join("style.css"); let user_cell: RefCell> = RefCell::new(None); bread_theme::gtk::apply_user_css(&user_css_path, &user_cell); @@ -353,7 +334,7 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { let list = ListBox::new(); list.set_selection_mode(SelectionMode::Browse); - for (idx, entry) in entries.iter().enumerate() { + for entry in &entries { let row = gtk4::ListBoxRow::new(); let hbox = GBox::new(Orientation::Horizontal, 0); hbox.set_margin_start(6); @@ -379,35 +360,9 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { row.set_child(Some(&hbox)); unsafe { row.set_data("entry", entry.clone()) }; - unsafe { row.set_data("initial_order", idx as u32) }; list.append(&row); } - // Sort by match quality + launch count when a query is active; - // fall back to insertion order (priority + launch frequency) when empty. - let sort_query = Rc::clone(&query_rc); - let sort_history = Rc::clone(&history_rc); - list.set_sort_func(move |row_a, row_b| { - let query = sort_query.borrow(); - if query.is_empty() { - let oa = unsafe { row_a.data::("initial_order").map_or(u32::MAX, |p| *p.as_ref()) }; - let ob = unsafe { row_b.data::("initial_order").map_or(u32::MAX, |p| *p.as_ref()) }; - return oa.cmp(&ob).into(); - } - let (Some(ea), Some(eb)) = (get_row_entry(row_a), get_row_entry(row_b)) else { - return std::cmp::Ordering::Equal.into(); - }; - let sa = fuzzy_score(&query, &ea); - let sb = fuzzy_score(&query, &eb); - let history = sort_history.borrow(); - let ca = history.count(&ea.name); - let cb = history.count(&eb.name); - sa.cmp(&sb) - .then(cb.cmp(&ca)) - .then(ea.name.to_lowercase().cmp(&eb.name.to_lowercase())) - .into() - }); - if let Some(first) = list.row_at_index(0) { list.select_row(Some(&first)); } @@ -418,11 +373,10 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { // Filter on keystroke let list_f = list.clone(); - let filter_query = Rc::clone(&query_rc); search.connect_changed(move |entry| { let text = entry.text(); let query = text.as_str(); - *filter_query.borrow_mut() = query.to_string(); + let mut first_vis: Option = None; let mut i = 0i32; while let Some(row) = list_f.row_at_index(i) { let vis = get_row_entry(&row) @@ -435,12 +389,11 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { }) .unwrap_or(false); row.set_visible(vis); + if vis && first_vis.is_none() { + first_vis = Some(row); + } i += 1; } - list_f.invalidate_sort(); - let first_vis = (0i32..).find_map(|j| { - list_f.row_at_index(j).filter(|r| r.is_visible()) - }); list_f.select_row(first_vis.as_ref()); }); @@ -449,7 +402,6 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { key_ctrl.set_propagation_phase(gtk4::PropagationPhase::Capture); let close_k = Rc::clone(&close_all); let list_k = list.clone(); - let history_k = Rc::clone(&history_rc); key_ctrl.connect_key_pressed(move |_, key, _, _| { use gtk4::gdk::Key; match key { @@ -460,8 +412,6 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { Key::Return | Key::KP_Enter => { if let Some(row) = list_k.selected_row() { if let Some(entry) = get_row_entry(&row) { - history_k.borrow_mut().increment(&entry.name); - history_k.borrow().save(); do_launch(&entry); close_k(); } @@ -508,11 +458,8 @@ fn run_ui(entries: Vec, css: String, history: LaunchHistory) { // Row click launches let close_a = Rc::clone(&close_all); - let history_a = Rc::clone(&history_rc); list.connect_row_activated(move |_, row| { if let Some(entry) = get_row_entry(row) { - history_a.borrow_mut().increment(&entry.name); - history_a.borrow().save(); do_launch(&entry); close_a(); } @@ -558,12 +505,11 @@ fn main() { .map(|c| c.priority.clone()) .unwrap_or_default(); - let history = LaunchHistory::load(); let manifest = load_manifest(); - let entries = load_sorted_entries(&manifest, &priority, &history); + let entries = load_sorted_entries(&manifest, &priority); let palette = load_palette(); let css = build_css(&palette); - run_ui(entries, css, history); + run_ui(entries, css); }