From 6daabe164343ff11689d221175fc7fd77c99b926 Mon Sep 17 00:00:00 2001 From: IG Date: Sun, 16 Jul 2023 22:50:53 +0100 Subject: [PATCH] log to file with timestamp --- bt/app/about_window.cpp | 4 ++-- bt/app/browser.h | 1 - bt/app/config_window.cpp | 18 ++++++++++-------- bt/app/pick_window.cpp | 1 - bt/app/rule_hit_log.cpp | 2 ++ bt/app/ui.cpp | 29 ++--------------------------- bt/app/ui.h | 2 -- bt/app/update_check.cpp | 5 ----- bt/bt.cpp | 17 ++++++++++++++--- docs/release-notes.md | 5 ++++- 10 files changed, 34 insertions(+), 50 deletions(-) diff --git a/bt/app/about_window.cpp b/bt/app/about_window.cpp index a37f280..00141d8 100644 --- a/bt/app/about_window.cpp +++ b/bt/app/about_window.cpp @@ -52,12 +52,12 @@ It super fast, extremely light on resources, completely free and open source.)") auto cmd_homepage = make_button(ICON_FA_HOUSE " Home"); cmd_homepage->on_pressed = [this](button&) { - ui::url_open(url_payload{APP_URL, "ui_about_home"}, ui::open_method::configured); + ui::url_open(url_payload{APP_URL}, ui::open_method::configured); }; same_line(); make_button(ICON_FA_GITHUB " GitHub")->on_pressed = [](button&) { - ui::url_open(url_payload{APP_GITHUB_URL, "ui_about_github"}, ui::open_method::configured); + ui::url_open(url_payload{APP_GITHUB_URL}, ui::open_method::configured); }; same_line(); diff --git a/bt/app/browser.h b/bt/app/browser.h index cb88ebc..8833f00 100644 --- a/bt/app/browser.h +++ b/bt/app/browser.h @@ -9,7 +9,6 @@ namespace bt { struct url_payload { std::string url; - std::string method; bool app_mode{false}; HWND source_window_handle; // handle of the system window where the click came from diff --git a/bt/app/config_window.cpp b/bt/app/config_window.cpp index 7f72fb1..bad64ed 100644 --- a/bt/app/config_window.cpp +++ b/bt/app/config_window.cpp @@ -36,6 +36,12 @@ namespace bt void config_window::init() { has_menu_space = true; + // restore from config + // todo: move more here + log_rule_hits = config::i.get_log_rule_hits(); + + // build UI + build_menu(); panel_no_browsers = make_child_window(); @@ -102,10 +108,6 @@ namespace bt assign_child(w_url_tester); w_url_tester->is_visible = false; w_url_tester->center(); - - // restore from config - // todo: move more here - log_rule_hits = config::i.get_log_rule_hits(); } void config_window::build_status_bar() { @@ -468,19 +470,19 @@ special keyword - %url% which is replaced by opening url.)"; } else if(mi.id == "update") { // todo: open direct url ui::url_open( - url_payload{string(APP_URL) + "#installing", "ui_newver"}, + url_payload{string(APP_URL) + "#installing"}, ui::open_method::configured); } else if(mi.id == "chrome_ex") { ui::url_open( - url_payload{APP_BROWSER_EXTENSION_CHROME_URL, "ui_chrome_ex"}, + url_payload{APP_BROWSER_EXTENSION_CHROME_URL}, ui::open_method::configured); } else if(mi.id == "firefox_ex") { ui::url_open( - url_payload{APP_BROWSER_EXTENSION_FIREFOX_URL, "ui_firefox_ex"}, + url_payload{APP_BROWSER_EXTENSION_FIREFOX_URL}, ui::open_method::configured); } else if(mi.id == "edge_ex") { ui::url_open( - url_payload{APP_BROWSER_EXTENSION_EDGE_URL, "ui_edge_ex"}, + url_payload{APP_BROWSER_EXTENSION_EDGE_URL}, ui::open_method::configured); } else if(mi.id == "picker") { config::i.set_picker_enabled(!mi.is_selected); diff --git a/bt/app/pick_window.cpp b/bt/app/pick_window.cpp index 67c2113..5135aec 100644 --- a/bt/app/pick_window.cpp +++ b/bt/app/pick_window.cpp @@ -110,7 +110,6 @@ namespace bt { }, true); rpt->bind(choices); rpt->on_item_clicked = [this](shared_ptr c, shared_ptr bi) { - up.method = "picker"; bi->launch(up); bi->popularity += 1; config::i.set_popularity(bi->long_id(), bi->popularity); diff --git a/bt/app/rule_hit_log.cpp b/bt/app/rule_hit_log.cpp index df9abab..e76a2bd 100644 --- a/bt/app/rule_hit_log.cpp +++ b/bt/app/rule_hit_log.cpp @@ -17,6 +17,7 @@ namespace bt { rule_hit_log::rule_hit_log() : path{get_file_path()}, stream(path, ofstream::out | ofstream::app | ofstream::ate), writer(stream) { if(stream.tellp() == 0) { writer.write_row(vector { + "timestamp", "browser_id", "browser_name", "profile_name", @@ -31,6 +32,7 @@ namespace bt { void rule_hit_log::write(const bt::url_payload& url, const bt::browser_match_result& bmr) { writer.write_row(vector{ + datetime::to_iso_8601(), bmr.bi->b->id, bmr.bi->b->name, bmr.bi->name, diff --git a/bt/app/ui.cpp b/bt/app/ui.cpp index 95bd107..0246fcd 100644 --- a/bt/app/ui.cpp +++ b/bt/app/ui.cpp @@ -29,8 +29,7 @@ namespace bt::ui { is_main_instance = true; t.add_constant("iid", config::i.get_iid()); - t.track(map - { + t.track(map { { "event", "start" } }, true); } @@ -93,7 +92,6 @@ namespace bt::ui { } if(method == open_method::pick) { - up.method = "pick"; picker(up, browser::to_instances(browser::get_cache())); } else { // silent or decide @@ -104,11 +102,9 @@ namespace bt::ui { up.app_mode = first_match.rule.app_mode; if(method == open_method::silent) { - up.method = "silent"; first_match.bi->launch(up); open_on_match_event(up, first_match); } else if(matches.size() == 1) { - up.method = "decide_single_match"; first_match.bi->launch(up); open_on_match_event(up, first_match); } else { @@ -130,9 +126,6 @@ namespace bt::ui { w->detach_on_close = true; w->on_open_changed = [](bool& is_open) { is_config_running = is_open; - if(!is_open) { - send_anonymous_config(); - } }; is_config_running = true; } @@ -168,7 +161,7 @@ namespace bt::ui { } void coffee(const string& from) { - ui::url_open(url_payload{CoffeePageUrl, "ui_coffee"}, ui::open_method::silent); + ui::url_open(url_payload{CoffeePageUrl}, ui::open_method::silent); } bool is_picker_hotkey_down() { @@ -180,22 +173,4 @@ namespace bt::ui { return false; } - - void send_anonymous_config() { - auto browsers = browser::get_cache(); - for(shared_ptr b : browsers) { - t.track(map { - { "event", "stat_browser" }, - { "id", b->id }, - { "name", b->name }, - { "is_system", b->is_system ? "y" : "n" }, - { "profile_count", to_string(b->instances.size()) }, - { "rule_count", to_string(b->get_total_rule_count()) } - }, false); - } - t.track(map { - { "event", "stat_ff_containers" }, - { "mode", config::firefox_container_mode_to_string(config::i.get_firefox_container_mode()) } - }, true); - } } \ No newline at end of file diff --git a/bt/app/ui.h b/bt/app/ui.h index 08f048f..9fefff9 100644 --- a/bt/app/ui.h +++ b/bt/app/ui.h @@ -48,6 +48,4 @@ namespace bt::ui void coffee(const std::string& from); bool is_picker_hotkey_down(); - - void send_anonymous_config(); } \ No newline at end of file diff --git a/bt/app/update_check.cpp b/bt/app/update_check.cpp index 7d3871d..f381a0b 100644 --- a/bt/app/update_check.cpp +++ b/bt/app/update_check.cpp @@ -10,11 +10,6 @@ using namespace std::chrono; namespace bt::app { bool has_new_version(std::string& latest_version_number) { - - win32::http h; - map headers; - int code = h.get_get_headers("https://bit.ly/3NMBvFA", headers); - ext::github gh; ext::github_release ghr = gh.get_latest_release("aloneguid", "bt"); if(!ghr.is_valid) return false; diff --git a/bt/bt.cpp b/bt/bt.cpp index 0977aca..f5b42e6 100644 --- a/bt/bt.cpp +++ b/bt/bt.cpp @@ -58,6 +58,12 @@ void execute(const string& data) { } } +void CALLBACK KeepAliveTimerProc(HWND hwnd, UINT message, UINT_PTR idTimer, DWORD dwTime) { + t.track(map { + { "event", "ping" } + }, true); +} + int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { if(bt::config::i.get_flag("debug_args") == "y") { @@ -125,7 +131,7 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { m.show(); break; case NIN_BALLOONUSERCLICK: - bt::ui::url_open(bt::url_payload{string(APP_URL) + "#installing", "baloon_click"}, bt::ui::open_method::configured); + bt::ui::url_open(bt::url_payload{string(APP_URL) + "#installing"}, bt::ui::open_method::configured); break; } break; @@ -141,7 +147,7 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { } else if(id == "contact") { bt::ui::contact(); } else if(id == "?") { - bt::ui::url_open(bt::url_payload{string(APP_URL), "shell_icon"}, bt::ui::open_method::configured); + bt::ui::url_open(bt::url_payload{string(APP_URL)}, bt::ui::open_method::configured); } } break; @@ -170,6 +176,11 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { execute(arg); + // set 1h + ::SetTimer(win32app.get_hwnd(), 1, + 1000 * 60 * 60, // ms * sec * min + KeepAliveTimerProc); + app_event.connect([&sni](const string& name, const string& arg1, const string& arg2) { if(name == "new_version") { sni.display_notification("New Version", fmt::format("Version {} is now available!", arg1)); @@ -186,7 +197,7 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { // check for new versions string vn; - if(bt::app::has_new_version(vn)) { + if(bt::app::should_check_new_version() && bt::app::has_new_version(vn)) { app_event("new_version", vn, ""); } diff --git a/docs/release-notes.md b/docs/release-notes.md index 1a0429e..e821f96 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,7 +2,10 @@ - Rule hits can can be optionally recorded to a CSV file (off by default). To enable, check `Settings`->`Log Rule Hits to File`. This creates `hit_log.csv` which you can open from the `File` menu. Feature is useful for recording your activity for further analysis to exporting to some analytical engine. -- Bug fixed - config window was not deleted from memory after closing it. +### Bugs Fixed + +- Config window was not deleted from memory after closing it. +- Update check was happening on every start instead of every 24 hours. ## 3.3.0