Skip to content

Commit

Permalink
add snapmaker login & logout
Browse files Browse the repository at this point in the history
  • Loading branch information
womendoushihaoyin committed Oct 15, 2024
1 parent 65578ce commit 040fae6
Show file tree
Hide file tree
Showing 8 changed files with 625 additions and 5 deletions.
1 change: 1 addition & 0 deletions localization/i18n/list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ src/slic3r/GUI/WipeTowerDialog.cpp
src/slic3r/GUI/wxExtensions.cpp
src/slic3r/GUI/wxMediaCtrl2.cpp
src/slic3r/GUI/WebUserLoginDialog.cpp
src/slic3r/GUI/WebSMUserLoginDialog.cpp
src/slic3r/GUI/WebGuideDialog.cpp
src/slic3r/GUI/KBShortcutsDialog.hpp
src/slic3r/GUI/KBShortcutsDialog.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ set(SLIC3R_GUI_SOURCES
GUI/WebGuideDialog.cpp
GUI/WebUserLoginDialog.cpp
GUI/WebUserLoginDialog.hpp
GUI/WebSMUserLoginDialog.cpp
GUI/WebSMUserLoginDialog.hpp
GUI/ConfigManipulation.cpp
GUI/ConfigManipulation.hpp
GUI/Field.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/slic3r/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "format.hpp"

#include "WebUserLoginDialog.hpp"
#include "WebSMUserLoginDialog.hpp"

#include "libslic3r/Print.hpp"

Expand Down Expand Up @@ -495,7 +496,8 @@ void login()
//LoginDialog dlg;
//dlg.ShowModal();

ZUserLogin dlg;
// ZUserLogin dlg;
SMUserLogin dlg;
dlg.run();
}

Expand Down
69 changes: 66 additions & 3 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3602,6 +3602,69 @@ wxString GUI_App::transition_tridid(int trid_id)
return wxString::Format("%s%d", maping_dict[id_index], id_suffix);
}

// SM
void GUI_App::sm_get_login_info() {
if (!m_login_userinfo.is_user_login() || m_login_userinfo.get_user_name().empty()) {
// default
json param;
param["command"] = "studio_useroffline";
param["sequece_id"] = "10001";
std::string logout_cmd = param.dump();
wxString strJS = wxString::Format("window.postMessage(%s)", logout_cmd);
GUI::wxGetApp().run_script(strJS);
} else {
json param;
param["command"] = "studio_userlogin";
param["sequece_id"] = "10001";
json data;
data["avatar"] = m_login_userinfo.get_user_icon_url();
data["name"] = m_login_userinfo.get_user_name();
param["data"] = data;
std::string login_cmd = param.dump();
wxString strJS = wxString::Format("window.postMessage(%s)", login_cmd);
GUI::wxGetApp().run_script(strJS);
}
mainframe->m_webview->SetLoginPanelVisibility(true);
}

void GUI_App::sm_request_login(bool show_user_info)
{
sm_ShowUserLogin();

if (show_user_info) {
sm_get_login_info();
}

}

void GUI_App::sm_ShowUserLogin(bool show)
{
// BBS: User Login Dialog
if (show) {
try {
if (!sm_login_dlg)
sm_login_dlg = new SMUserLogin();
else {
delete sm_login_dlg;
sm_login_dlg = new SMUserLogin();
}
sm_login_dlg->ShowModal();
} catch (std::exception&) {
;
}
} else {
if (sm_login_dlg)
sm_login_dlg->EndModal(wxID_OK);
}
}

void GUI_App::sm_request_user_logout()
{
if (m_login_userinfo.is_user_login()) {
m_login_userinfo.set_user_login(false);
}
}

//BBS
void GUI_App::request_login(bool show_user_info)
{
Expand Down Expand Up @@ -3734,17 +3797,17 @@ std::string GUI_App::handle_web_request(std::string cmd)
}
else if (command_str.compare("get_login_info") == 0) {
CallAfter([this] {
get_login_info();
sm_get_login_info();
});
}
else if (command_str.compare("homepage_login_or_register") == 0) {
CallAfter([this] {
this->request_login(true);
this->sm_request_login(true);
});
}
else if (command_str.compare("homepage_logout") == 0) {
CallAfter([this] {
wxGetApp().request_user_logout();
wxGetApp().sm_request_user_logout();
});
}
else if (command_str.compare("homepage_modeldepot") == 0) {
Expand Down
31 changes: 31 additions & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "slic3r/Utils/NetworkAgent.hpp"
#include "slic3r/GUI/WebViewDialog.hpp"
#include "slic3r/GUI/WebUserLoginDialog.hpp"
#include "slic3r/GUI/WebSMUserLoginDialog.hpp"
#include "slic3r/GUI/BindDialog.hpp"
#include "slic3r/GUI/HMS.hpp"
#include "slic3r/GUI/Jobs/UpgradeNetworkJob.hpp"
Expand Down Expand Up @@ -293,6 +294,7 @@ class GUI_App : public wxApp

// login widget
ZUserLogin* login_dlg { nullptr };
SMUserLogin* sm_login_dlg{ nullptr };

VersionInfo version_info;
VersionInfo privacy_version_info;
Expand Down Expand Up @@ -443,6 +445,33 @@ class GUI_App : public wxApp
void get_login_info();
bool is_user_login();

// SM
struct SMUserInfo
{
public:
bool is_user_login() { return m_login; }
void set_user_login(bool login) { m_login = login; }

std::string get_user_name() { return m_login_user_name; }
void set_user_name(const std::string& name) { m_login_user_name = name; }

std::string get_user_token() { return m_login_user_token; }
void set_user_token(const std::string& token) { m_login_user_token = token; }

std::string get_user_icon_url() { return m_login_user_icon_url; }
void set_user_icon_url(const std::string& url) { m_login_user_icon_url = url; }
private:
std::string m_login_user_name = "";
std::string m_login_user_token = "";
std::string m_login_user_icon_url = "";
bool m_login = false;
};
SMUserInfo* sm_get_userinfo() { return &m_login_userinfo; }
void sm_get_login_info();
void sm_request_login(bool show_user_info = false);
void sm_ShowUserLogin(bool show = true);
void sm_request_user_logout();

void request_user_login(int online_login = 0);
void request_user_handle(int online_login = 0);
void request_user_logout();
Expand Down Expand Up @@ -698,6 +727,8 @@ class GUI_App : public wxApp
boost::optional<Semver> m_last_config_version;
bool m_config_corrupted { false };
std::string m_open_method;

SMUserInfo m_login_userinfo;
};

DECLARE_APP(GUI_App)
Expand Down
Loading

0 comments on commit 040fae6

Please sign in to comment.