Skip to content

Commit

Permalink
log to file with timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Jul 16, 2023
1 parent 238e00f commit 6daabe1
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 50 deletions.
4 changes: 2 additions & 2 deletions bt/app/about_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion bt/app/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions bt/app/config_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion bt/app/pick_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ namespace bt {
}, true);
rpt->bind(choices);
rpt->on_item_clicked = [this](shared_ptr<container> c, shared_ptr<browser_instance> bi) {
up.method = "picker";
bi->launch(up);
bi->popularity += 1;
config::i.set_popularity(bi->long_id(), bi->popularity);
Expand Down
2 changes: 2 additions & 0 deletions bt/app/rule_hit_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
"timestamp",
"browser_id",
"browser_name",
"profile_name",
Expand All @@ -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<string>{
datetime::to_iso_8601(),
bmr.bi->b->id,
bmr.bi->b->name,
bmr.bi->name,
Expand Down
29 changes: 2 additions & 27 deletions bt/app/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ namespace bt::ui {
is_main_instance = true;
t.add_constant("iid", config::i.get_iid());

t.track(map<string, string>
{
t.track(map<string, string> {
{ "event", "start" }
}, true);
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand All @@ -180,22 +173,4 @@ namespace bt::ui {

return false;
}

void send_anonymous_config() {
auto browsers = browser::get_cache();
for(shared_ptr<browser> b : browsers) {
t.track(map<string, string> {
{ "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<string, string> {
{ "event", "stat_ff_containers" },
{ "mode", config::firefox_container_mode_to_string(config::i.get_firefox_container_mode()) }
}, true);
}
}
2 changes: 0 additions & 2 deletions bt/app/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ namespace bt::ui
void coffee(const std::string& from);

bool is_picker_hotkey_down();

void send_anonymous_config();
}
5 changes: 0 additions & 5 deletions bt/app/update_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ using namespace std::chrono;

namespace bt::app {
bool has_new_version(std::string& latest_version_number) {

win32::http h;
map<string, string> 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;
Expand Down
17 changes: 14 additions & 3 deletions bt/bt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ void execute(const string& data) {
}
}

void CALLBACK KeepAliveTimerProc(HWND hwnd, UINT message, UINT_PTR idTimer, DWORD dwTime) {
t.track(map<string, string> {
{ "event", "ping" }
}, true);
}

int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {

if(bt::config::i.get_flag("debug_args") == "y") {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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, "");
}

Expand Down
5 changes: 4 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6daabe1

Please sign in to comment.