From 4c83c8918c1c5f32fb0b507995d6f4accfd8ed50 Mon Sep 17 00:00:00 2001 From: IG Date: Thu, 18 Jul 2024 10:59:06 +0100 Subject: [PATCH] Refactor bt.cpp & update build to 4.0.2 - Updated the build version in `build.yml` from `4.0.1` to `4.0.2`. - In `bt.cpp`, refactored the picker logic to use a structured decision-making process. This includes handling conditions like `force_picker`, `picker_always`, `picker_on_conflict`, and `picker_on_no_rule`. Added `pick_reason` to improve logging and decision transparency. - Updated the subproject commit in `common` to include changes up to a new commit marked as `-dirty`. - Added release notes for version `4.0.2` in `release-notes.md`, highlighting the bug fix for picker visibility issues, credited to @Mythrix for their contribution in resolving issue `#40`. --- .github/workflows/build.yml | 2 +- bt/bt.cpp | 30 ++++++++++++++++++++++++------ docs/release-notes.md | 3 +++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 01d9f68..cbffdba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: 'Build' env: - VERSION: 4.0.1 + VERSION: 4.0.2 BUILD_TYPE: Release ARCH: x64 VCPKG_CONFIG: Release diff --git a/bt/bt.cpp b/bt/bt.cpp index b043105..b84f012 100644 --- a/bt/bt.cpp +++ b/bt/bt.cpp @@ -29,19 +29,37 @@ void track_event(string name) { void open(bt::url_payload up, bool force_picker = false) { - bool picker_hotkeyed = - g_config.picker_always || - bt::ui::picker_app::is_hotkey_down(); - g_pipeline.process(up); - if(force_picker || picker_hotkeyed) { + // decision whether to show picker or not + bool show_picker{force_picker}; + string pick_reason; + if(!show_picker) { + if(g_config.picker_always) { + show_picker = true; + pick_reason = "always"; + } else if(bt::ui::picker_app::is_hotkey_down()) { + show_picker = true; + pick_reason = "hotkey"; + } else if(g_config.picker_on_conflict || g_config.picker_on_no_rule) { + auto matches = bt::browser::match(g_config.browsers, up, g_config.default_profile_long_id); + if(g_config.picker_on_conflict && matches.size() > 1) { + show_picker = true; + pick_reason = "conflict"; + } else if(g_config.picker_on_no_rule && matches[0].rule.is_fallback) { + show_picker = true; + pick_reason = "no rule"; + } + } + } + + if(show_picker) { bt::ui::picker_app app{up.url}; auto bi = app.run(); if(bi) { bt::url_opener::open(bi, up); if(g_config.log_rule_hits) { - bt::rule_hit_log::i.write(up, bi, ""); + bt::rule_hit_log::i.write(up, bi, "picker:" + pick_reason); } } } else { diff --git a/docs/release-notes.md b/docs/release-notes.md index d957890..0e6668b 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,3 +1,6 @@ +## 4.0.2 +Fixed a bug where picker would not show up if it was configured to be shown on conflict or always. Thanks to @Mythrix in #40. + ## 4.0.1 - Browsers installed via Windows Store (Firefox) are automatically detected and added to the list.