From 88eb5a76c1613fc6b00d63d4059a8e68403fdb72 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Tue, 15 Apr 2025 10:33:48 +0800 Subject: [PATCH] ENH: save privacy policy check history JIRA: STUDIO-11574 Change-Id: I519602f8d8468cfeada313035db76b2fa2b280d4 Signed-off-by: Stone Li --- src/slic3r/GUI/GUI_App.cpp | 39 +++++++++++++++++++++++++++++++ src/slic3r/GUI/GUI_App.hpp | 1 + src/slic3r/GUI/Preferences.cpp | 1 + src/slic3r/GUI/WebGuideDialog.cpp | 7 ++++++ src/slic3r/Utils/NetworkAgent.cpp | 3 +++ 5 files changed, 51 insertions(+) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a2ba47c98..192a044e9 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -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) { DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 72ee4e4cb..d0482f935 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -464,6 +464,7 @@ public: void on_user_login(wxCommandEvent &evt); void on_user_login_handle(wxCommandEvent& evt); void enable_user_preset_folder(bool enable); + void save_privacy_policy_history(bool agree, std::string source = ""); // BBS bool is_studio_active(); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 54838a336..c1cc8c8e8 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -738,6 +738,7 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa agent->track_remove_files(); } } + wxGetApp().save_privacy_policy_history(!checkbox->GetValue(), "preferences"); app_config->save(); } else if (param == "auto_stop_liveview") { diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index 3057948de..fafc36811 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -393,8 +393,10 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt) if (strAction == "agree") { m_PrivacyUse = "true"; + wxGetApp().save_privacy_policy_history(true, "user_privacy_choice"); } else { m_PrivacyUse = "false"; + wxGetApp().save_privacy_policy_history(false, "user_privacy_choice"); } m_GuideFinish = true; @@ -460,6 +462,11 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt) } } 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(); std::string oldregion = m_ProfileJson["region"]; diff --git a/src/slic3r/Utils/NetworkAgent.cpp b/src/slic3r/Utils/NetworkAgent.cpp index 2a5c97b46..02e309c43 100644 --- a/src/slic3r/Utils/NetworkAgent.cpp +++ b/src/slic3r/Utils/NetworkAgent.cpp @@ -1514,6 +1514,9 @@ int NetworkAgent::track_event(std::string evt_key, std::string content) if (!this->enable_track) return 0; + if (!this->is_user_login()) + return 0; + int ret = 0; if (network_agent && track_event_ptr) { ret = track_event_ptr(network_agent, evt_key, content);