ENH: save privacy policy check history

JIRA: STUDIO-11574

Change-Id: I519602f8d8468cfeada313035db76b2fa2b280d4
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li 2025-04-15 10:33:48 +08:00 committed by lane.wei
parent 9beeebdba1
commit 88eb5a76c1
5 changed files with 51 additions and 0 deletions

View File

@ -4791,6 +4791,45 @@ void GUI_App::enable_user_preset_folder(bool enable)
} }
} }
void GUI_App::save_privacy_policy_history(bool agree, std::string source)
{
json j;
wxDateTime::TimeZone tz(wxDateTime::Local);
long offset = tz.GetOffset();
std::string timezone = get_timezone_utc_hm(offset);
std::time_t now = std::time(nullptr);
std::tm* utc_time = std::gmtime(&now);
std::ostringstream time_str;
time_str << std::put_time(utc_time, "%Y-%m-%d %H:%M:%S") << " " << timezone;
j["action"] = agree ? "agree" : "skip";
j["source"] = source;
if (app_config)
j["uuid"] = app_config->get("slicer_uuid");
j["time"] = time_str.str();
j["user_id"] = "default_user";
if (m_agent && agree) {
if (!m_agent->get_user_id().empty())
j["user_id"] = m_agent->get_user_id();
m_agent->track_event("privacy_policy", j.dump());
}
BOOST_LOG_TRIVIAL(info) << "privacy_policy: source = " << source << ", value = " << j.dump();
boost::filesystem::path dir = (boost::filesystem::path(Slic3r::data_dir()) / "track").make_preferred();
std::string dir_str = dir.string();
if (!fs::exists(dir_str)) {
fs::create_directory(dir_str);
}
std::string path = (boost::filesystem::path(Slic3r::data_dir()) / "track" / ("history.txt")).make_preferred().string();
boost::nowide::ofstream c;
c.open(path, std::ios::app);
if (c.is_open()) {
c << j.dump() << "\n";
c.close();
}
}
void GUI_App::on_set_selected_machine(wxCommandEvent &evt) void GUI_App::on_set_selected_machine(wxCommandEvent &evt)
{ {
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();

View File

@ -464,6 +464,7 @@ public:
void on_user_login(wxCommandEvent &evt); void on_user_login(wxCommandEvent &evt);
void on_user_login_handle(wxCommandEvent& evt); void on_user_login_handle(wxCommandEvent& evt);
void enable_user_preset_folder(bool enable); void enable_user_preset_folder(bool enable);
void save_privacy_policy_history(bool agree, std::string source = "");
// BBS // BBS
bool is_studio_active(); bool is_studio_active();

View File

@ -738,6 +738,7 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa
agent->track_remove_files(); agent->track_remove_files();
} }
} }
wxGetApp().save_privacy_policy_history(!checkbox->GetValue(), "preferences");
app_config->save(); app_config->save();
} }
else if (param == "auto_stop_liveview") { else if (param == "auto_stop_liveview") {

View File

@ -393,8 +393,10 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt)
if (strAction == "agree") { if (strAction == "agree") {
m_PrivacyUse = "true"; m_PrivacyUse = "true";
wxGetApp().save_privacy_policy_history(true, "user_privacy_choice");
} else { } else {
m_PrivacyUse = "false"; m_PrivacyUse = "false";
wxGetApp().save_privacy_policy_history(false, "user_privacy_choice");
} }
m_GuideFinish = true; m_GuideFinish = true;
@ -460,6 +462,11 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt)
} }
} }
else if (strCmd == "user_guide_finish") { else if (strCmd == "user_guide_finish") {
if (wxGetApp().app_config) {
std::string last = wxGetApp().app_config->get(std::string(m_SectionName.mb_str()), "privacyuse");
if (m_PrivacyUse != last)
wxGetApp().save_privacy_policy_history(m_PrivacyUse == "true", "user_guide");
}
SaveProfile(); SaveProfile();
std::string oldregion = m_ProfileJson["region"]; std::string oldregion = m_ProfileJson["region"];

View File

@ -1514,6 +1514,9 @@ int NetworkAgent::track_event(std::string evt_key, std::string content)
if (!this->enable_track) if (!this->enable_track)
return 0; return 0;
if (!this->is_user_login())
return 0;
int ret = 0; int ret = 0;
if (network_agent && track_event_ptr) { if (network_agent && track_event_ptr) {
ret = track_event_ptr(network_agent, evt_key, content); ret = track_event_ptr(network_agent, evt_key, content);