Skip to content

Commit

Permalink
NEW: check privacy update
Browse files Browse the repository at this point in the history
Change-Id: I260fbc20cdddbdadd38f1470a2e7050ee1ed14cd
Signed-off-by: Stone Li <[email protected]>
  • Loading branch information
tao.jin authored and lanewei120 committed Feb 22, 2023
1 parent b1a310c commit 240d106
Show file tree
Hide file tree
Showing 10 changed files with 460 additions and 6 deletions.
24 changes: 24 additions & 0 deletions resources/tooltip/privacyupdate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="./main.css" />
<script src="./main.js"></script>
</head>
<body style="background-color: #F8F8F8;">
<div class="container markdown-body" id="contents"></div>
</body>
<script>
const resizeOberver = new ResizeObserver((entities) => {
const height = entities[0].contentRect.height
document.title = height.toFixed()
})
resizeOberver.observe(document.querySelector('#contents'))
window.showMarkdownFile = function (file) {
$.get(file, function( data ) {
window.showMarkdown(encodeURIComponent(data));
});
}
</script>
</html>
4 changes: 4 additions & 0 deletions src/libslic3r/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ void AppConfig::set_defaults()
set("mouse_supported", "mouse left/mouse middle/mouse right");
}

if (get("privacy_version").empty()) {
set("privacy_version", "00.00.00.00");
}

if (get("rotate_view").empty()) {
set("rotate_view", "none/mouse left");
}
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ set(SLIC3R_GUI_SOURCES
GUI/PublishDialog.hpp
GUI/RecenterDialog.cpp
GUI/RecenterDialog.hpp
GUI/PrivacyUpdateDialog.cpp
GUI/PrivacyUpdateDialog.hpp
GUI/BonjourDialog.cpp
GUI/BonjourDialog.hpp
GUI/BindDialog.cpp
Expand Down
142 changes: 140 additions & 2 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#include "WebDownPluginDlg.hpp"
#include "WebGuideDialog.hpp"
#include "ReleaseNote.hpp"
#include "PrivacyUpdateDialog.hpp"
#include "ModelMall.hpp"

//#ifdef WIN32
Expand Down Expand Up @@ -1125,6 +1126,10 @@ void GUI_App::post_init()

//BBS: check new version
this->check_new_version();
//BBS: check privacy version
if (is_user_login())
this->check_privacy_version(0);

});
}

Expand Down Expand Up @@ -1663,7 +1668,7 @@ void GUI_App::init_networking_callbacks()
if (m_agent) {
//set callbacks
m_agent->set_on_user_login_fn([this](int online_login, bool login) {
GUI::wxGetApp().request_user_login(online_login);
GUI::wxGetApp().request_user_handle(online_login);
});

m_agent->set_on_server_connected_fn([this]() {
Expand Down Expand Up @@ -1995,6 +2000,14 @@ void GUI_App::init_http_extra_header()
m_agent->set_extra_http_header(extra_headers);
}

void GUI_App::update_http_extra_header()
{
std::map<std::string, std::string> extra_headers = get_extra_header();
Slic3r::Http::set_extra_headers(extra_headers);
if (m_agent)
m_agent->set_extra_http_header(extra_headers);
}

std::string GUI_App::get_local_models_path()
{
std::string local_path = "";
Expand Down Expand Up @@ -2344,6 +2357,9 @@ bool GUI_App::on_init_inner()

Bind(EVT_SET_SELECTED_MACHINE, &GUI_App::on_set_selected_machine, this);
Bind(EVT_USER_LOGIN, &GUI_App::on_user_login, this);
Bind(EVT_USER_LOGIN_HANDLE, &GUI_App::on_user_login_handle, this);
Bind(EVT_CHECK_PRIVACY_VER, &GUI_App::on_check_privacy_update, this);
Bind(EVT_CHECK_PRIVACY_SHOW, &GUI_App::show_check_privacy_dlg, this);

Bind(EVT_SHOW_IP_DIALOG, &GUI_App::show_ip_address_enter_dialog_handler, this);

Expand Down Expand Up @@ -3354,6 +3370,13 @@ bool GUI_App::check_login()
return result;
}

void GUI_App::request_user_handle(int online_login)
{
auto evt = new wxCommandEvent(EVT_USER_LOGIN_HANDLE);
evt->SetInt(online_login);
wxQueueEvent(this, evt);
}

void GUI_App::request_user_login(int online_login)
{
auto evt = new wxCommandEvent(EVT_USER_LOGIN);
Expand Down Expand Up @@ -3718,7 +3741,7 @@ void GUI_App::on_set_selected_machine(wxCommandEvent &evt)
dev->set_selected_machine(m_agent->get_user_selected_machine());
}

void GUI_App::on_user_login(wxCommandEvent &evt)
void GUI_App::on_user_login_handle(wxCommandEvent &evt)
{
if (!m_agent) { return; }

Expand Down Expand Up @@ -3760,6 +3783,14 @@ void GUI_App::on_user_login(wxCommandEvent &evt)
}
}

void GUI_App::on_user_login(wxCommandEvent &evt)
{
if (!m_agent) { return; }
int online_login = evt.GetInt();
// check privacy before handle
check_privacy_version(online_login);
}

bool GUI_App::is_studio_active()
{
auto curr_time = std::chrono::system_clock::now();
Expand Down Expand Up @@ -3889,6 +3920,113 @@ void GUI_App::set_skip_version(bool skip)
}
}

void GUI_App::show_check_privacy_dlg(wxCommandEvent& evt)
{
int online_login = evt.GetInt();
PrivacyUpdateDialog privacy_dlg(this->mainframe, wxID_ANY, _L("Privacy Policy"));
privacy_dlg.Bind(EVT_PRIVACY_UPDATE_CONFIRM, [this, online_login](wxCommandEvent &e) {
app_config->set("privacy_version", privacy_version_info.version_str);
app_config->set_bool("privacy_update_checked", true);
app_config->save();
request_user_handle(online_login);
});
privacy_dlg.Bind(EVT_PRIVACY_UPDATE_CANCEL, [this](wxCommandEvent &e) {
app_config->set_bool("privacy_update_checked", false);
app_config->save();
if (m_agent) {
m_agent->user_logout();
}
});

privacy_dlg.set_text(privacy_version_info.description);
privacy_dlg.on_show();
}

void GUI_App::on_show_check_privacy_dlg(int online_login)
{
auto evt = new wxCommandEvent(EVT_CHECK_PRIVACY_SHOW);
evt->SetInt(online_login);
wxQueueEvent(this, evt);
}

bool GUI_App::check_privacy_update()
{
if (privacy_version_info.version_str.empty() || privacy_version_info.description.empty()
|| privacy_version_info.url.empty()) {
return false;
}

std::string local_privacy_ver = app_config->get("privacy_version");
auto curr_version = Semver::parse(local_privacy_ver);
auto remote_version = Semver::parse(privacy_version_info.version_str);
if (curr_version && remote_version) {
if (*remote_version > *curr_version || app_config->get("privacy_update_checked") != "true") {
return true;
}
}
return false;
}

void GUI_App::on_check_privacy_update(wxCommandEvent& evt)
{
int online_login = evt.GetInt();
bool result = check_privacy_update();
if (result)
on_show_check_privacy_dlg(online_login);
else
request_user_handle(online_login);
}

void GUI_App::check_privacy_version(int online_login)
{
update_http_extra_header();
std::string query_params = "?policy/privacy=00.00.00.00";
std::string url = get_http_url(app_config->get_country_code()) + query_params;
Slic3r::Http http = Slic3r::Http::get(url);

http.header("accept", "application/json")
.timeout_connect(TIMEOUT_CONNECT)
.timeout_max(TIMEOUT_RESPONSE)
.on_complete([this, online_login](std::string body, unsigned) {
try {
json j = json::parse(body);
if (j.contains("message")) {
if (j["message"].get<std::string>() == "success") {
if (j.contains("resources")) {
for (auto it = j["resources"].begin(); it != j["resources"].end(); it++) {
if (it->contains("type")) {
if ((*it)["type"] == std::string("policy/privacy")
&& it->contains("version")
&& it->contains("description")
&& it->contains("url")
&& it->contains("force_update")) {
privacy_version_info.version_str = (*it)["version"].get<std::string>();
privacy_version_info.description = (*it)["description"].get<std::string>();
privacy_version_info.url = (*it)["url"].get<std::string>();
privacy_version_info.force_upgrade = (*it)["force_update"].get<bool>();
break;
}
}
}
CallAfter([this, online_login]() {
auto evt = new wxCommandEvent(EVT_CHECK_PRIVACY_VER);
evt->SetInt(online_login);
wxQueueEvent(this, evt);
});
}
}
}
}
catch (...) {
request_user_handle(online_login);
}
})
.on_error([this, online_login](std::string body, std::string error, unsigned int status) {
request_user_handle(online_login);
BOOST_LOG_TRIVIAL(error) << "check privacy version error" << body;
}).perform();
}

void GUI_App::no_new_version()
{
wxCommandEvent* evt = new wxCommandEvent(EVT_SHOW_NO_NEW_VERSION);
Expand Down
12 changes: 11 additions & 1 deletion src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class GUI_App : public wxApp
ZUserLogin* login_dlg { nullptr };

VersionInfo version_info;
VersionInfo privacy_version_info;
static std::string version_display;
HMSQuery *hms_query { nullptr };

Expand Down Expand Up @@ -395,7 +396,8 @@ class GUI_App : public wxApp
void get_login_info();
bool is_user_login();

void request_user_login(int online_login);
void request_user_login(int online_login = 0);
void request_user_handle(int online_login = 0);
void request_user_logout();
int request_user_unbind(std::string dev_id);
std::string handle_web_request(std::string cmd);
Expand All @@ -410,6 +412,7 @@ class GUI_App : public wxApp
void on_http_error(wxCommandEvent &evt);
void on_set_selected_machine(wxCommandEvent& evt);
void on_user_login(wxCommandEvent &evt);
void on_user_login_handle(wxCommandEvent& evt);
void enable_user_preset_folder(bool enable);

// BBS
Expand All @@ -434,6 +437,12 @@ class GUI_App : public wxApp
void start_http_server();
void stop_http_server();

void on_show_check_privacy_dlg(int online_login = 0);
void show_check_privacy_dlg(wxCommandEvent& evt);
void on_check_privacy_update(wxCommandEvent &evt);
bool check_privacy_update();
void check_privacy_version(int online_login = 0);

static bool catch_error(std::function<void()> cb, const std::string& err);

void persist_window_geometry(wxTopLevelWindow *window, bool default_maximized = false);
Expand Down Expand Up @@ -593,6 +602,7 @@ class GUI_App : public wxApp
//BBS set extra header for http request
std::map<std::string, std::string> get_extra_header();
void init_http_extra_header();
void update_http_extra_header();
bool check_older_app_config(Semver current_version, bool backup);
void copy_older_config();
void window_pos_save(wxTopLevelWindow* window, const std::string &name);
Expand Down
3 changes: 3 additions & 0 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ namespace GUI {
wxDEFINE_EVENT(EVT_SELECT_TAB, wxCommandEvent);
wxDEFINE_EVENT(EVT_HTTP_ERROR, wxCommandEvent);
wxDEFINE_EVENT(EVT_USER_LOGIN, wxCommandEvent);
wxDEFINE_EVENT(EVT_USER_LOGIN_HANDLE, wxCommandEvent);
wxDEFINE_EVENT(EVT_CHECK_PRIVACY_VER, wxCommandEvent);
wxDEFINE_EVENT(EVT_CHECK_PRIVACY_SHOW, wxCommandEvent);
wxDEFINE_EVENT(EVT_SHOW_IP_DIALOG, wxCommandEvent);
wxDEFINE_EVENT(EVT_SET_SELECTED_MACHINE, wxCommandEvent);
wxDEFINE_EVENT(EVT_UPDATE_PRESET_CB, SimpleEvent);
Expand Down
3 changes: 3 additions & 0 deletions src/slic3r/GUI/MainFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ class MainFrame : public DPIFrame

wxDECLARE_EVENT(EVT_HTTP_ERROR, wxCommandEvent);
wxDECLARE_EVENT(EVT_USER_LOGIN, wxCommandEvent);
wxDECLARE_EVENT(EVT_USER_LOGIN_HANDLE, wxCommandEvent);
wxDECLARE_EVENT(EVT_CHECK_PRIVACY_VER, wxCommandEvent);
wxDECLARE_EVENT(EVT_CHECK_PRIVACY_SHOW, wxCommandEvent);
wxDECLARE_EVENT(EVT_SHOW_IP_DIALOG, wxCommandEvent);
wxDECLARE_EVENT(EVT_SET_SELECTED_MACHINE, wxCommandEvent);
wxDECLARE_EVENT(EVT_UPDATE_PRESET_CB, SimpleEvent);
Expand Down
Loading

0 comments on commit 240d106

Please sign in to comment.