mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 18:27:58 -06:00
ENH:add track events
Change-Id: I7fb685013f243d6394a94a3c9500016b247ea0a8
This commit is contained in:
parent
c582e64e0d
commit
6f298ac6f1
2 changed files with 93 additions and 8 deletions
|
@ -1132,6 +1132,34 @@ void GUI_App::post_init()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//BBS: check crash log
|
||||||
|
auto log_dir_path = boost::filesystem::path(data_dir()) / "log";
|
||||||
|
if (boost::filesystem::exists(log_dir_path))
|
||||||
|
{
|
||||||
|
boost::filesystem::directory_iterator end_iter;
|
||||||
|
for (boost::filesystem::directory_iterator iter(log_dir_path); iter != end_iter; ++iter)
|
||||||
|
{
|
||||||
|
std::string file_name = iter->path().stem().string();
|
||||||
|
if (boost::starts_with(file_name, "crash")) {
|
||||||
|
std::ifstream ifs(iter->path().string(), ios::in);
|
||||||
|
std::stringstream data;
|
||||||
|
data << ifs.rdbuf();
|
||||||
|
ifs.close();
|
||||||
|
|
||||||
|
NetworkAgent* agent = wxGetApp().getAgent();
|
||||||
|
json j;
|
||||||
|
j["time"] = file_name.substr(file_name.find("crash") + strlen("crash") + 1);
|
||||||
|
j["verion"] = std::string(SLIC3R_VERSION);
|
||||||
|
j["content"] = data.str();
|
||||||
|
if (agent) {
|
||||||
|
agent->track_event("studio_crash", j.dump());
|
||||||
|
}
|
||||||
|
std::string new_file_name = file_name.insert(0, "_done_");
|
||||||
|
boost::filesystem::rename(iter->path(), iter->path().parent_path() / boost::filesystem::path(new_file_name + iter->path().extension().string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_networking_need_update) {
|
if (m_networking_need_update) {
|
||||||
//updating networking
|
//updating networking
|
||||||
int ret = updating_bambu_networking();
|
int ret = updating_bambu_networking();
|
||||||
|
@ -1389,10 +1417,19 @@ static std::string decode(std::string const& extra, std::string const& path = {}
|
||||||
int GUI_App::download_plugin(std::string name, std::string package_name, InstallProgressFn pro_fn, WasCancelledFn cancel_fn)
|
int GUI_App::download_plugin(std::string name, std::string package_name, InstallProgressFn pro_fn, WasCancelledFn cancel_fn)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
json j;
|
||||||
|
std::string err_msg;
|
||||||
|
|
||||||
// get country_code
|
// get country_code
|
||||||
AppConfig* app_config = wxGetApp().app_config;
|
AppConfig* app_config = wxGetApp().app_config;
|
||||||
if (!app_config)
|
if (!app_config) {
|
||||||
|
j["result"] = "failed";
|
||||||
|
j["error_msg"] = "app_config is nullptr";
|
||||||
|
if (m_agent) {
|
||||||
|
m_agent->track_event("networkplugin_download", j.dump());
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "[download_plugin]: enter";
|
BOOST_LOG_TRIVIAL(info) << "[download_plugin]: enter";
|
||||||
m_networking_cancel_update = false;
|
m_networking_cancel_update = false;
|
||||||
|
@ -1452,21 +1489,32 @@ int GUI_App::download_plugin(std::string name, std::string package_name, Install
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}).on_error(
|
}).on_error(
|
||||||
[&result](std::string body, std::string error, unsigned int status) {
|
[&result, &err_msg](std::string body, std::string error, unsigned int status) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "[download_plugin 1] on_error: " << error<<", body = " << body;
|
BOOST_LOG_TRIVIAL(error) << "[download_plugin 1] on_error: " << error<<", body = " << body;
|
||||||
|
err_msg += "[download_plugin 1] on_error: " + error + ", body = " + body;
|
||||||
result = -1;
|
result = -1;
|
||||||
}).perform_sync();
|
}).perform_sync();
|
||||||
|
|
||||||
bool cancel = false;
|
bool cancel = false;
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
j["result"] = "failed";
|
||||||
|
j["error_msg"] = err_msg;
|
||||||
|
if (m_agent) {
|
||||||
|
m_agent->track_event("networkplugin_download", j.dump());
|
||||||
|
}
|
||||||
if (pro_fn) pro_fn(InstallStatusDownloadFailed, 0, cancel);
|
if (pro_fn) pro_fn(InstallStatusDownloadFailed, 0, cancel);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (download_url.empty()) {
|
if (download_url.empty()) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "[download_plugin 1]: no availaible plugin found for this app version: " << SLIC3R_VERSION;
|
BOOST_LOG_TRIVIAL(info) << "[download_plugin 1]: no available plugin found for this app version: " << SLIC3R_VERSION;
|
||||||
if (pro_fn) pro_fn(InstallStatusDownloadFailed, 0, cancel);
|
if (pro_fn) pro_fn(InstallStatusDownloadFailed, 0, cancel);
|
||||||
|
j["result"] = "failed";
|
||||||
|
j["error_msg"] = "[download_plugin 1]: no available plugin found for this app version: " + std::string(SLIC3R_VERSION);
|
||||||
|
if (m_agent) {
|
||||||
|
m_agent->track_event("networkplugin_download", j.dump());
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (pro_fn) {
|
else if (pro_fn) {
|
||||||
|
@ -1475,6 +1523,11 @@ int GUI_App::download_plugin(std::string name, std::string package_name, Install
|
||||||
|
|
||||||
if (m_networking_cancel_update || cancel) {
|
if (m_networking_cancel_update || cancel) {
|
||||||
BOOST_LOG_TRIVIAL(info) << boost::format("[download_plugin 1]: %1%, cancelled by user") % __LINE__;
|
BOOST_LOG_TRIVIAL(info) << boost::format("[download_plugin 1]: %1%, cancelled by user") % __LINE__;
|
||||||
|
j["result"] = "failed";
|
||||||
|
j["error_msg"] = (boost::format("[download_plugin 1]: %1%, cancelled by user") % __LINE__).str();
|
||||||
|
if (m_agent) {
|
||||||
|
m_agent->track_event("networkplugin_download", j.dump());
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "[download_plugin] get_url = " << download_url;
|
BOOST_LOG_TRIVIAL(info) << "[download_plugin] get_url = " << download_url;
|
||||||
|
@ -1483,7 +1536,7 @@ int GUI_App::download_plugin(std::string name, std::string package_name, Install
|
||||||
Slic3r::Http http = Slic3r::Http::get(download_url);
|
Slic3r::Http http = Slic3r::Http::get(download_url);
|
||||||
int reported_percent = 0;
|
int reported_percent = 0;
|
||||||
http.on_progress(
|
http.on_progress(
|
||||||
[this, &pro_fn, cancel_fn, &result, &reported_percent](Slic3r::Http::Progress progress, bool& cancel) {
|
[this, &pro_fn, cancel_fn, &result, &reported_percent, &err_msg](Slic3r::Http::Progress progress, bool& cancel) {
|
||||||
int percent = 0;
|
int percent = 0;
|
||||||
if (progress.dltotal != 0)
|
if (progress.dltotal != 0)
|
||||||
percent = progress.dlnow * 50 / progress.dltotal;
|
percent = progress.dlnow * 50 / progress.dltotal;
|
||||||
|
@ -1498,8 +1551,10 @@ int GUI_App::download_plugin(std::string name, std::string package_name, Install
|
||||||
if (cancel_fn())
|
if (cancel_fn())
|
||||||
cancel = true;
|
cancel = true;
|
||||||
|
|
||||||
if (cancel)
|
if (cancel) {
|
||||||
|
err_msg += "[download_plugin] cancel";
|
||||||
result = -1;
|
result = -1;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.on_complete([&pro_fn, tmp_path, target_file_path](std::string body, unsigned status) {
|
.on_complete([&pro_fn, tmp_path, target_file_path](std::string body, unsigned status) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "[download_plugin 2] completed";
|
BOOST_LOG_TRIVIAL(info) << "[download_plugin 2] completed";
|
||||||
|
@ -1511,13 +1566,19 @@ int GUI_App::download_plugin(std::string name, std::string package_name, Install
|
||||||
fs::rename(tmp_path, target_file_path);
|
fs::rename(tmp_path, target_file_path);
|
||||||
if (pro_fn) pro_fn(InstallStatusDownloadCompleted, 80, cancel);
|
if (pro_fn) pro_fn(InstallStatusDownloadCompleted, 80, cancel);
|
||||||
})
|
})
|
||||||
.on_error([&pro_fn, &result](std::string body, std::string error, unsigned int status) {
|
.on_error([&pro_fn, &result, &err_msg](std::string body, std::string error, unsigned int status) {
|
||||||
bool cancel = false;
|
bool cancel = false;
|
||||||
if (pro_fn) pro_fn(InstallStatusDownloadFailed, 0, cancel);
|
if (pro_fn) pro_fn(InstallStatusDownloadFailed, 0, cancel);
|
||||||
BOOST_LOG_TRIVIAL(error) << "[download_plugin 2] on_error: " << error<<", body = " << body;
|
BOOST_LOG_TRIVIAL(error) << "[download_plugin 2] on_error: " << error<<", body = " << body;
|
||||||
|
err_msg += "[download_plugin 2] on_error: " + error + ", body = " + body;
|
||||||
result = -1;
|
result = -1;
|
||||||
});
|
});
|
||||||
http.perform_sync();
|
http.perform_sync();
|
||||||
|
j["result"] = result < 0 ? "failed" : "success";
|
||||||
|
j["error_msg"] = err_msg;
|
||||||
|
if (m_agent) {
|
||||||
|
m_agent->track_event("networkplugin_download", j.dump());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2544,12 +2605,18 @@ bool GUI_App::on_init_inner()
|
||||||
if (m_studio_active != curr_studio_active) {
|
if (m_studio_active != curr_studio_active) {
|
||||||
if (curr_studio_active) {
|
if (curr_studio_active) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "studio is active, start to subscribe";
|
BOOST_LOG_TRIVIAL(info) << "studio is active, start to subscribe";
|
||||||
if (m_agent)
|
if (m_agent) {
|
||||||
|
json j = json::object();
|
||||||
m_agent->start_subscribe("app");
|
m_agent->start_subscribe("app");
|
||||||
|
m_agent->track_event("mqtt_active", j.dump());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(info) << "studio is inactive, stop to subscribe";
|
BOOST_LOG_TRIVIAL(info) << "studio is inactive, stop to subscribe";
|
||||||
if (m_agent)
|
if (m_agent) {
|
||||||
|
json j = json::object();
|
||||||
m_agent->stop_subscribe("app");
|
m_agent->stop_subscribe("app");
|
||||||
|
m_agent->track_event("mqtt_inactive", j.dump());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_studio_active = curr_studio_active;
|
m_studio_active = curr_studio_active;
|
||||||
}
|
}
|
||||||
|
|
|
@ -514,6 +514,24 @@ void MonitorPanel::show_status(int status)
|
||||||
|
|
||||||
if (last_status == status)
|
if (last_status == status)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (last_status & (int)MonitorStatus::MONITOR_CONNECTING != 0) {
|
||||||
|
NetworkAgent* agent = wxGetApp().getAgent();
|
||||||
|
json j;
|
||||||
|
j["dev_id"] = obj ? obj->dev_id : "obj_nullptr";
|
||||||
|
if (status & (int)MonitorStatus::MONITOR_DISCONNECTED != 0) {
|
||||||
|
j["result"] = "failed";
|
||||||
|
if (agent) {
|
||||||
|
agent->track_event("connect_dev", j.dump());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (status & (int)MonitorStatus::MONITOR_NORMAL != 0) {
|
||||||
|
j["result"] = "success";
|
||||||
|
if (agent) {
|
||||||
|
agent->track_event("connect_dev", j.dump());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
last_status = status;
|
last_status = status;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "monitor: show_status = " << status;
|
BOOST_LOG_TRIVIAL(info) << "monitor: show_status = " << status;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue