mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
NEW: add service to check network state
Change-Id: Ic2072d0e141767d3acc617f6011ca62eccaf6278 Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
80a3e17663
commit
cb5f7843c0
4 changed files with 92 additions and 0 deletions
|
@ -2752,6 +2752,9 @@ bool GUI_App::on_init_inner()
|
|||
}
|
||||
});
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "start_check_network_state...";
|
||||
start_check_network_state();
|
||||
|
||||
m_initialized = true;
|
||||
|
||||
flush_logs();
|
||||
|
@ -4114,6 +4117,82 @@ void GUI_App::on_user_login_handle(wxCommandEvent &evt)
|
|||
}
|
||||
}
|
||||
|
||||
void GUI_App::start_check_network_state()
|
||||
{
|
||||
boost::thread* test_microsoft = new boost::thread([this] {
|
||||
start_test_url("www.microsoft.com");
|
||||
});
|
||||
boost::thread* test_apple = new boost::thread([this] {
|
||||
start_test_url("www.apple.com");
|
||||
});
|
||||
boost::thread* test_amazon = new boost::thread([this] {
|
||||
start_test_url("www.amazon.com");
|
||||
});
|
||||
|
||||
m_check_network_thread = boost::thread([this] {
|
||||
int sec_count = 1;
|
||||
while (!m_is_closing) {
|
||||
if (sec_count % 10 == 0) {
|
||||
bool link_result = check_network_state();
|
||||
if (!link_result) {
|
||||
BOOST_LOG_TRIVIAL(info) << "link_result = " << link_result;
|
||||
}
|
||||
}
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
|
||||
sec_count++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool GUI_App::check_network_state()
|
||||
{
|
||||
bool result = false;
|
||||
for (auto link : test_url_state) {
|
||||
result = result | link.second;
|
||||
}
|
||||
if (m_agent) {
|
||||
if (result)
|
||||
m_agent->track_update_property("link_state", "1");
|
||||
else
|
||||
m_agent->track_update_property("link_state", "0");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void GUI_App::start_test_url(std::string url)
|
||||
{
|
||||
int sec_count = 0;
|
||||
while (!m_is_closing) {
|
||||
if (sec_count % 10 == 0) {
|
||||
Slic3r::Http http = Slic3r::Http::get(url);
|
||||
int result = -1;
|
||||
http.timeout_max(5)
|
||||
.on_complete([&result](std::string body, unsigned status) {
|
||||
try {
|
||||
if (status == 200) {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
;
|
||||
}
|
||||
})
|
||||
.on_error([](std::string body, std::string error, unsigned int status) {
|
||||
;
|
||||
}).perform_sync();
|
||||
|
||||
if (result == 0) {
|
||||
test_url_state[url] = true;
|
||||
} else {
|
||||
test_url_state[url] = false;
|
||||
}
|
||||
}
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
|
||||
sec_count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GUI_App::check_track_enable()
|
||||
{
|
||||
if (app_config && app_config->get("firstguide", "privacyuse") == "true") {
|
||||
|
|
|
@ -293,12 +293,16 @@ private:
|
|||
bool m_adding_script_handler { false };
|
||||
bool m_side_popup_status{false};
|
||||
HttpServer m_http_server;
|
||||
|
||||
boost::thread m_check_network_thread;
|
||||
public:
|
||||
void check_filaments_in_blacklist(std::string tag_supplier, std::string tag_material, bool& in_blacklist, std::string& action, std::string& info);
|
||||
std::string get_local_models_path();
|
||||
bool OnInit() override;
|
||||
bool initialized() const { return m_initialized; }
|
||||
|
||||
std::map<std::string, bool> test_url_state;
|
||||
|
||||
//BBS: remove GCodeViewer as seperate APP logic
|
||||
explicit GUI_App();
|
||||
//explicit GUI_App(EAppMode mode = EAppMode::Editor);
|
||||
|
@ -420,6 +424,9 @@ public:
|
|||
void on_set_selected_machine(wxCommandEvent& evt);
|
||||
void on_user_login(wxCommandEvent &evt);
|
||||
void on_user_login_handle(wxCommandEvent& evt);
|
||||
void start_check_network_state();
|
||||
bool check_network_state();
|
||||
void start_test_url(std::string url);
|
||||
void enable_user_preset_folder(bool enable);
|
||||
|
||||
// BBS
|
||||
|
|
|
@ -1227,6 +1227,8 @@ int NetworkAgent::track_event(std::string evt_key, std::string content)
|
|||
|
||||
int NetworkAgent::track_header(std::string header)
|
||||
{
|
||||
if (!this->enable_track)
|
||||
return 0;
|
||||
int ret = 0;
|
||||
if (network_agent && track_header_ptr) {
|
||||
ret = track_header_ptr(network_agent, header);
|
||||
|
@ -1238,6 +1240,9 @@ int NetworkAgent::track_header(std::string header)
|
|||
|
||||
int NetworkAgent::track_update_property(std::string name, std::string value, std::string type)
|
||||
{
|
||||
if (!this->enable_track)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
if (network_agent && track_update_property_ptr) {
|
||||
ret = track_update_property_ptr(network_agent, name, value, type);
|
||||
|
|
|
@ -178,6 +178,7 @@ public:
|
|||
int track_event(std::string evt_key, std::string content);
|
||||
int track_header(std::string header);
|
||||
int track_update_property(std::string name, std::string value, std::string type = "string");
|
||||
bool get_track_enable() { return enable_track; }
|
||||
private:
|
||||
bool enable_track = false;
|
||||
void* network_agent { nullptr };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue