feature add sub for privacy update flags for web control.

This commit is contained in:
alves
2026-01-13 16:07:52 +08:00
parent 6b8b8b0e76
commit 4ff14ce96e
6 changed files with 85 additions and 8 deletions

View File

@@ -7063,7 +7063,7 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage
}
auto isAgree = wxGetApp().app_config->get("app", "privacy_policy_isagree");
set_privacy_policy(isAgree == "true");
user_update_privacy_notify(isAgree == "true");
BOOST_LOG_TRIVIAL(warning) << "run_wizard changed the privacy policy with: " << (isAgree);
return res;
}
@@ -7268,6 +7268,23 @@ void GUI_App::cache_notify(const std::string& key, const json& res)
}
}
void GUI_App::user_update_privacy_notify(const bool& res)
{
set_privacy_policy(res);
json data;
data["privacy_policy_isagree"] = res;
for (const auto& instance : m_user_update_privacy_subscribers) {
auto ptr = instance.second.lock();
if (ptr) {
ptr->m_res_data = data;
ptr->send_to_js();
}
}
}
void GUI_App::user_login_notify(const json& res)
{
@@ -7283,7 +7300,7 @@ void GUI_App::user_login_notify(const json& res)
bool GUI_App::config_wizard_startup()
{
auto isAgree = wxGetApp().app_config->get("app", "privacy_policy_isagree");
set_privacy_policy(isAgree == "true");
user_update_privacy_notify(isAgree == "true");
BOOST_LOG_TRIVIAL(warning) << "config_wizard_startup changed the privacy policy with: " << (isAgree);
if (!m_app_conf_exists || preset_bundle->printers.only_default_printers()) {
BOOST_LOG_TRIVIAL(info) << "run wizard...";

View File

@@ -834,7 +834,7 @@ public:
std::unordered_map<void*, std::weak_ptr<SSWCP_Instance>> m_user_login_subscribers;
std::unordered_map<void*, std::weak_ptr<SSWCP_Instance>> m_device_card_subscribers;
std::unordered_map<void*, std::weak_ptr<SSWCP_Instance>> m_page_state_subscribers;
std::unordered_map<void*, std::weak_ptr<SSWCP_Instance>> m_user_update_privacy_subscribers;
struct CachePairCompare
{
bool operator()(const std::pair<void*, std::weak_ptr<SSWCP_Instance>>& lhs,
@@ -850,7 +850,7 @@ public:
void device_card_notify(const json& res);
void page_state_notify_webview(wxWebView* webview, const std::string& state);
void cache_notify(const std::string& key, const json& res);
void user_update_privacy_notify(const bool& res);
public:
bool sm_disconnect_current_machine(bool need_reload_printerview = true);

View File

@@ -752,7 +752,7 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa
{
app_config->set("app", "privacy_policy_isagree", checkbox->GetValue());
BOOST_LOG_TRIVIAL(warning) <<"create_item_checkbox changed the privacy policy with: "<<(checkbox->GetValue()?"true" : "false");
set_privacy_policy(checkbox->GetValue());
wxGetApp().user_update_privacy_notify(checkbox->GetValue());
}
// if (param == "staff_pick_switch") {
// bool pbool = app_config->get("staff_pick_switch") == "true";

View File

@@ -1175,6 +1175,7 @@ void SSWCP_Instance::sw_UnsubscribeAll() {
wxGetApp().m_recent_file_subscribers.clear();
wxGetApp().m_user_login_subscribers.clear();
wxGetApp().m_cache_subscribers.clear();
wxGetApp().m_user_update_privacy_subscribers.clear();
send_to_js();
finish_job();
@@ -1217,6 +1218,15 @@ void SSWCP_Instance::sw_Webview_Unsubscribe() {
}
}
auto& privacy_map = wxGetApp().m_user_update_privacy_subscribers;
for (auto iter = privacy_map.begin(); iter != privacy_map.end();) {
if (iter->first == m_webview) {
iter = privacy_map.erase(iter);
} else {
iter++;
}
}
send_to_js();
finish_job();
}
@@ -1233,6 +1243,7 @@ void SSWCP_Instance::sw_Unsubscribe_Filter() {
auto& device_map = wxGetApp().m_device_card_subscribers;
auto& login_map = wxGetApp().m_user_login_subscribers;
auto& privacy_map = wxGetApp().m_user_update_privacy_subscribers;
auto& recent_file_map = wxGetApp().m_recent_file_subscribers;
auto& cache_map = wxGetApp().m_cache_subscribers;
@@ -1271,6 +1282,23 @@ void SSWCP_Instance::sw_Unsubscribe_Filter() {
}
}
for (auto iter = privacy_map.begin(); iter != privacy_map.end();) {
if (iter->first == m_webview) {
auto ptr = iter->second.lock();
if (ptr) {
if (ptr->m_event_id == event_id) {
iter = privacy_map.erase(iter);
} else {
iter++;
}
} else {
iter = privacy_map.erase(iter);
}
} else {
iter++;
}
}
for (auto iter = recent_file_map.begin(); iter != recent_file_map.end();) {
if (iter->first == m_webview) {
auto ptr = iter->second.lock();
@@ -1339,7 +1367,26 @@ void SSWCP_Instance::sw_Unsubscribe_Filter() {
iter++;
}
}
} else if (cmd == "sw_SubscribeLocalDevices") {
} else if (cmd == UPDATE_PRIVACY_STATUS) {
for (auto iter = privacy_map.begin(); iter != privacy_map.end();) {
if (iter->first == m_webview) {
auto ptr = iter->second.lock();
if (ptr) {
if (event_id == "" || (event_id != "" && event_id == ptr->m_event_id)) {
iter = privacy_map.erase(iter);
} else {
iter++;
}
} else {
iter = privacy_map.erase(iter);
}
} else {
iter++;
}
}
}else if (cmd == "sw_SubscribeLocalDevices") {
for (auto iter = device_map.begin(); iter != device_map.end();) {
if (iter->first == m_webview) {
auto ptr = iter->second.lock();
@@ -1373,7 +1420,7 @@ void SSWCP_Instance::sw_Unsubscribe_Filter() {
iter++;
}
}
}
}
send_to_js();
finish_job();
@@ -5941,6 +5988,15 @@ void SSWCP::on_webview_delete(wxWebView* view)
}
}
auto& privacy_map = wxGetApp().m_user_update_privacy_subscribers;
for (auto iter = privacy_map.begin(); iter != privacy_map.end();) {
if (iter->first == view) {
iter = privacy_map.erase(iter);
} else {
iter++;
}
}
auto& recent_file_map = wxGetApp().m_recent_file_subscribers;
for (auto iter = recent_file_map.begin(); iter != recent_file_map.end();) {
if (iter->first == view) {

View File

@@ -23,6 +23,8 @@ using namespace nlohmann;
namespace asio = boost::asio;
using tcp = asio::ip::tcp;
#define UPDATE_PRIVACY_STATUS "sw_SubUserUpdatePrivacy"
namespace Slic3r { namespace GUI {
class WCP_Logger
@@ -525,6 +527,8 @@ private:
void sw_SubscribeUserLoginState();
void sw_SubUserUpdatePrivacy();
};
// Instance class for homepage business

View File

@@ -651,7 +651,7 @@ int GuideFrame::SaveProfile()
// m_MainPtr->app_config->set(std::string(m_SectionName.mb_str()), "privacyuse", "0");
m_MainPtr->app_config->set("app", "privacy_policy_isagree", PrivacyUse);
BOOST_LOG_TRIVIAL(warning) << "SaveProfile changed the privacy policy with: " << (PrivacyUse ? "true" : "false");
set_privacy_policy(PrivacyUse);
wxGetApp().user_update_privacy_notify(PrivacyUse);
m_MainPtr->app_config->set("region", m_Region);
m_MainPtr->app_config->set_bool("stealth_mode", StealthMode);