mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-29 19:52:02 +08:00
Merge branch 'jb_dev_servers_config'
This commit is contained in:
commit
f86d329a70
@ -68,6 +68,7 @@
|
||||
|
||||
#ifdef SLIC3R_GUI
|
||||
#include "slic3r/GUI/GUI_Init.hpp"
|
||||
#include "slic3r/Utils/ServiceConfig.hpp"
|
||||
#endif /* SLIC3R_GUI */
|
||||
|
||||
using namespace Slic3r;
|
||||
@ -181,6 +182,9 @@ int CLI::run(int argc, char **argv)
|
||||
return 1;
|
||||
|
||||
#ifdef SLIC3R_GUI
|
||||
if (m_config.has("webdev")) {
|
||||
Utils::ServiceConfig::instance().set_webdev_enabled(m_config.opt_bool("webdev"));
|
||||
}
|
||||
std::vector<std::string>::iterator it;
|
||||
bool opengl_aa = false;
|
||||
it = std::find(m_actions.begin(), m_actions.end(), "opengl-aa");
|
||||
|
@ -5667,6 +5667,10 @@ CLIMiscConfigDef::CLIMiscConfigDef()
|
||||
"For example. loglevel=2 logs fatal, error and warning level messages.");
|
||||
def->min = 0;
|
||||
|
||||
def = this->add("webdev", coBool);
|
||||
def->label = L("Enable webdev tools");
|
||||
def->tooltip = L("Enable webdev tools");
|
||||
|
||||
#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(SLIC3R_GUI)
|
||||
def = this->add("sw_renderer", coBool);
|
||||
def->label = L("Render with a software renderer");
|
||||
|
@ -374,6 +374,8 @@ set(SLIC3R_GUI_SOURCES
|
||||
Utils/Secrets.cpp
|
||||
Utils/PrusaConnect.hpp
|
||||
Utils/PrusaConnect.cpp
|
||||
Utils/ServiceConfig.hpp
|
||||
Utils/ServiceConfig.cpp
|
||||
)
|
||||
|
||||
find_package(NanoSVG REQUIRED)
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "../Utils/PrintHost.hpp"
|
||||
#include "../Utils/FixModelByWin10.hpp"
|
||||
#include "../Utils/UndoRedo.hpp"
|
||||
#include "../Utils/ServiceConfig.hpp"
|
||||
#include "RemovableDriveManager.hpp"
|
||||
#include "BitmapCache.hpp"
|
||||
#include "BonjourDialog.hpp"
|
||||
@ -653,7 +654,7 @@ void PhysicalPrinterDialog::update(bool printer_change)
|
||||
text_ctrl* printhost_win = printhost_field ? dynamic_cast<text_ctrl*>(printhost_field->getWindow()) : nullptr;
|
||||
if (!m_opened_as_connect && printhost_win && m_last_host_type != htPrusaConnect){
|
||||
m_stored_host = printhost_win->GetValue();
|
||||
printhost_win->SetValue(L"https://connect.prusa3d.com");
|
||||
printhost_win->SetValue(from_u8(Utils::ServiceConfig::instance().connect_url()));
|
||||
}
|
||||
} else {
|
||||
m_printhost_browse_btn->Show();
|
||||
@ -888,10 +889,11 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
||||
text_ctrl* printhost_win = printhost_field ? dynamic_cast<text_ctrl*>(printhost_field->getWindow()) : nullptr;
|
||||
const auto opt = m_config->option<ConfigOptionEnum<PrintHostType>>("host_type");
|
||||
if (opt->value == htPrusaConnect) {
|
||||
if (printhost_win && printhost_win->GetValue() != L"https://connect.prusa3d.com"){
|
||||
InfoDialog msg(this, _L("Warning"), _L("URL of Prusa Connect is different from https://connect.prusa3d.com. Do you want to continue?"), true, wxYES_NO);
|
||||
auto& sc = Utils::ServiceConfig::instance();
|
||||
if (printhost_win && printhost_win->GetValue() != GUI::from_u8(sc.connect_url())){
|
||||
InfoDialog msg(this, _L("Warning"), GUI::format(_L("URL of Prusa Connect is different from %1%. Do you want to continue?"), sc.connect_url()), true, wxYES_NO);
|
||||
if(msg.ShowModal() != wxID_YES){
|
||||
printhost_win->SetValue(L"https://connect.prusa3d.com");
|
||||
printhost_win->SetValue(GUI::from_u8(Utils::ServiceConfig::instance().connect_url()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "PresetArchiveDatabase.hpp"
|
||||
|
||||
#include "slic3r/Utils/Http.hpp"
|
||||
#include "slic3r/Utils/ServiceConfig.hpp"
|
||||
#include "slic3r/GUI/format.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/Plater.hpp"
|
||||
@ -866,11 +867,7 @@ namespace {
|
||||
bool sync_inner(std::string& manifest)
|
||||
{
|
||||
bool ret = false;
|
||||
#ifdef SLIC3R_REPO_URL
|
||||
std::string url = SLIC3R_REPO_URL;
|
||||
#else
|
||||
std::string url = "https://preset-repo-api.prusa3d.com/v1/repos";
|
||||
#endif
|
||||
std::string url = Utils::ServiceConfig::instance().preset_repo_repos_url();
|
||||
auto http = Http::get(std::move(url));
|
||||
add_authorization_header(http);
|
||||
http
|
||||
|
@ -322,7 +322,8 @@ void UserAccountCommunication::on_uuid_map_success()
|
||||
}
|
||||
|
||||
wxString UserAccountCommunication::get_login_redirect_url() {
|
||||
const std::string AUTH_HOST = "https://account.prusa3d.com";
|
||||
auto& sc = Utils::ServiceConfig::instance();
|
||||
const std::string AUTH_HOST = sc.account_url();
|
||||
const std::string CLIENT_ID = client_id();
|
||||
const std::string REDIRECT_URI = "prusaslicer://login";
|
||||
CodeChalengeGenerator ccg;
|
||||
|
@ -98,7 +98,7 @@ private:
|
||||
void wakeup_session_thread();
|
||||
void init_session_thread();
|
||||
void login_redirect();
|
||||
std::string client_id() const { return "oamhmhZez7opFosnwzElIgE2oGgI2iJORSkw587O"; }
|
||||
std::string client_id() const { return Utils::ServiceConfig::instance().account_client_id(); }
|
||||
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "slic3r/Utils/ServiceConfig.hpp"
|
||||
|
||||
#include <queue>
|
||||
#include <map>
|
||||
@ -108,18 +109,19 @@ public:
|
||||
, m_polling_action(polling_enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY)
|
||||
|
||||
{
|
||||
auto& sc = Utils::ServiceConfig::instance();
|
||||
|
||||
// do not forget to add delete to destructor
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY] = std::make_unique<DummyUserAction>();
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_REFRESH_TOKEN] = std::make_unique<UserActionPost>("EXCHANGE_TOKENS", "https://account.prusa3d.com/o/token/");
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CODE_FOR_TOKEN] = std::make_unique<UserActionPost>("EXCHANGE_TOKENS", "https://account.prusa3d.com/o/token/");
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID] = std::make_unique<UserActionGetWithEvent>("USER_ID", "https://account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN] = std::make_unique<UserActionGetWithEvent>("TEST_ACCESS_TOKEN", "https://account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique<UserActionGetWithEvent>("TEST_CONNECTION", "https://account.prusa3d.com/api/v1/me/", wxEVT_NULL, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", "https://connect.prusa3d.com/slicer/status", EVT_UA_PRUSACONNECT_STATUS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTER_MODELS", "https://connect.prusa3d.com/slicer/printer_list", EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique<UserActionGetWithEvent>("AVATAR", "https://media.printables.com/media/", EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID] = std::make_unique<UserActionGetWithEvent>("USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID", "https://connect.prusa3d.com/app/printers/", EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_REFRESH_TOKEN] = std::make_unique<UserActionPost>("EXCHANGE_TOKENS", sc.account_token_url());
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CODE_FOR_TOKEN] = std::make_unique<UserActionPost>("EXCHANGE_TOKENS", sc.account_token_url());
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID] = std::make_unique<UserActionGetWithEvent>("USER_ID", sc.account_me_url(), EVT_UA_ID_USER_SUCCESS, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN] = std::make_unique<UserActionGetWithEvent>("TEST_ACCESS_TOKEN", sc.account_me_url(), EVT_UA_ID_USER_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique<UserActionGetWithEvent>("TEST_CONNECTION", sc.account_me_url(), wxEVT_NULL, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", sc.connect_status_url(), EVT_UA_PRUSACONNECT_STATUS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTER_MODELS", sc.connect_printer_list_url(), EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique<UserActionGetWithEvent>("AVATAR", sc.media_url(), EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID] = std::make_unique<UserActionGetWithEvent>("USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID", sc.connect_printers_url(), EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, EVT_UA_FAIL);
|
||||
}
|
||||
~UserAccountSession()
|
||||
{
|
||||
@ -162,7 +164,7 @@ private:
|
||||
void cancel_queue();
|
||||
void code_exchange_fail_callback(const std::string& body);
|
||||
void token_success_callback(const std::string& body);
|
||||
std::string client_id() const { return "oamhmhZez7opFosnwzElIgE2oGgI2iJORSkw587O"; }
|
||||
std::string client_id() const { return Utils::ServiceConfig::instance().account_client_id(); }
|
||||
|
||||
// false prevents action queu to be processed - no communication is done
|
||||
// sets to true by init_with_code or enqueue_action call
|
||||
|
@ -108,6 +108,10 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url, const
|
||||
|
||||
// Create the webview
|
||||
m_browser = WebView::CreateWebView(this, /*m_default_url*/ GUI::format_wxstr("file://%1%/web/%2%.html", boost::filesystem::path(resources_dir()).generic_string(), m_loading_html), m_script_message_hadler_names);
|
||||
if (Utils::ServiceConfig::instance().webdev_enabled()) {
|
||||
m_browser->EnableContextMenu();
|
||||
m_browser->EnableAccessToDevTools();
|
||||
}
|
||||
if (!m_browser) {
|
||||
wxStaticText* text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser."));
|
||||
topsizer->Add(text, 0, wxALIGN_LEFT | wxBOTTOM, 10);
|
||||
@ -576,7 +580,7 @@ void ConnectRequestHandler::on_connect_action_request_open_in_browser(const std:
|
||||
}
|
||||
|
||||
ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent)
|
||||
: WebViewPanel(parent, L"https://connect.prusa3d.com/", { "_prusaSlicer" }, "connect_loading")
|
||||
: WebViewPanel(parent, GUI::from_u8(Utils::ServiceConfig::instance().connect_url()), { "_prusaSlicer" }, "connect_loading")
|
||||
{
|
||||
//m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new WebViewHandler("https")));
|
||||
|
||||
@ -645,12 +649,14 @@ wxString ConnectWebViewPanel::get_login_script(bool refresh)
|
||||
.then(function (resp) {
|
||||
console.log('Login resp', resp);
|
||||
resp.text()
|
||||
.then(function (json) { console.log('Login resp body', json); })
|
||||
.then(function (json) { console.log('Login resp body', json); return json; })
|
||||
.then(function (body) {
|
||||
if (resp.status >= 400) errorHandler({status: resp.status, body});
|
||||
});
|
||||
})
|
||||
.catch(errorHandler);
|
||||
.catch(function (err){
|
||||
errorHandler({message: err.message, stack: err.stack});
|
||||
});
|
||||
)",
|
||||
#endif
|
||||
access_token
|
||||
@ -862,6 +868,10 @@ WebViewDialog::WebViewDialog(wxWindow* parent, const wxString& url, const wxStri
|
||||
|
||||
// Create the webview
|
||||
m_browser = WebView::CreateWebView(this, GUI::format_wxstr("file://%1%/web/%2%.html", boost::filesystem::path(resources_dir()).generic_string(), m_loading_html), m_script_message_hadler_names);
|
||||
if (Utils::ServiceConfig::instance().webdev_enabled()) {
|
||||
m_browser->EnableContextMenu();
|
||||
m_browser->EnableAccessToDevTools();
|
||||
}
|
||||
if (!m_browser) {
|
||||
wxStaticText* text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser."));
|
||||
topsizer->Add(text, 0, wxALIGN_LEFT | wxBOTTOM, 10);
|
||||
@ -1218,7 +1228,7 @@ void WebViewDialog::EndModal(int retCode)
|
||||
|
||||
PrinterPickWebViewDialog::PrinterPickWebViewDialog(wxWindow* parent, std::string& ret_val)
|
||||
: WebViewDialog(parent
|
||||
, L"https://connect.prusa3d.com/slicer-select-printer"
|
||||
, GUI::from_u8(Utils::ServiceConfig::instance().connect_select_printer_url())
|
||||
, _L("Choose a printer")
|
||||
, wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 2, 50 * wxGetApp().em_unit()))
|
||||
,{"_prusaSlicer"}
|
||||
@ -1354,7 +1364,7 @@ void LoginWebViewDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
|
||||
LogoutWebViewDialog::LogoutWebViewDialog(wxWindow *parent)
|
||||
: WebViewDialog(parent
|
||||
, L"https://account.prusa3d.com/logout"
|
||||
, GUI::from_u8(Utils::ServiceConfig::instance().account_logout_url())
|
||||
, _L("Logout dialog")
|
||||
, wxSize(std::max(parent->GetClientSize().x / 4, 10 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 4, 10 * wxGetApp().em_unit()))
|
||||
, {})
|
||||
|
@ -78,7 +78,7 @@ bool PrusaConnectNew::test(wxString& curl_msg) const
|
||||
{
|
||||
// Test is not used by upload and gets list of files on a device.
|
||||
const std::string name = get_name();
|
||||
std::string url = GUI::format("https://connect.prusa3d.com/app/teams/%1%/files?printer_uuid=%2%", m_team_id, m_uuid);
|
||||
std::string url = GUI::format("%1%/%2%/files?printer_uuid=%3%", Utils::ServiceConfig::instance().connect_teams_url(), m_team_id, m_uuid);
|
||||
const std::string access_token = GUI::wxGetApp().plater()->get_user_account()->get_access_token();
|
||||
BOOST_LOG_TRIVIAL(info) << GUI::format("%1%: Get files/raw at: %2%", name, url);
|
||||
bool res = true;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define slic3r_PrusaConnect_hpp_
|
||||
|
||||
#include "PrintHost.hpp"
|
||||
#include "ServiceConfig.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
/*
|
||||
#include <string>
|
||||
@ -32,7 +33,7 @@ public:
|
||||
bool has_auto_discovery() const override { return true; }
|
||||
bool can_test() const override { return true; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const override { return PrintHostPostUploadAction::StartPrint | PrintHostPostUploadAction::QueuePrint; }
|
||||
std::string get_host() const override { return "https://connect.prusa3d.com"; }
|
||||
std::string get_host() const override { return Utils::ServiceConfig::instance().connect_url(); }
|
||||
bool get_storage(wxArrayString& storage_path, wxArrayString& storage_name) const override;
|
||||
//const std::string& get_apikey() const { return m_apikey; }
|
||||
//const std::string& get_cafile() const { return m_cafile; }
|
||||
|
44
src/slic3r/Utils/ServiceConfig.cpp
Normal file
44
src/slic3r/Utils/ServiceConfig.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "ServiceConfig.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Slic3r::Utils {
|
||||
|
||||
void update_from_env(std::string& dest, const char* env_name, bool remove_trailing_slash=false)
|
||||
{
|
||||
const char* env_val = std::getenv(env_name);
|
||||
if (env_val == nullptr || std::strlen(env_val) == 0)
|
||||
return;
|
||||
|
||||
dest = env_val;
|
||||
if (remove_trailing_slash) {
|
||||
auto idx = dest.find_last_not_of('/');
|
||||
if (idx != std::string::npos && idx + 1 < dest.length())
|
||||
dest.erase(idx + 1, std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
ServiceConfig::ServiceConfig()
|
||||
: m_connect_url("https://connect.prusa3d.com")
|
||||
, m_account_url("https://account.prusa3d.com")
|
||||
, m_account_client_id("oamhmhZez7opFosnwzElIgE2oGgI2iJORSkw587O")
|
||||
, m_media_url("https://media.printables.com")
|
||||
, m_preset_repo_url("https://preset-repo-api.prusa3d.com") {
|
||||
#ifdef SLIC3R_REPO_URL
|
||||
m_preset_repo_url = SLIC3R_REPO_URL;
|
||||
#endif
|
||||
|
||||
update_from_env(m_connect_url, "PRUSA_CONNECT_URL", true);
|
||||
update_from_env(m_account_url, "PRUSA_ACCOUNT_URL", true);
|
||||
update_from_env(m_account_client_id, "PRUSA_ACCOUNT_CLIENT_ID");
|
||||
update_from_env(m_media_url, "PRUSA_MEDIA_URL", true);
|
||||
update_from_env(m_preset_repo_url, "PRUSA_PRESET_REPO_URL", true);
|
||||
}
|
||||
|
||||
ServiceConfig& ServiceConfig::instance()
|
||||
{
|
||||
static ServiceConfig inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
}
|
43
src/slic3r/Utils/ServiceConfig.hpp
Normal file
43
src/slic3r/Utils/ServiceConfig.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Slic3r::Utils {
|
||||
|
||||
class ServiceConfig {
|
||||
ServiceConfig();
|
||||
public:
|
||||
const std::string& connect_url() const { return m_connect_url; }
|
||||
|
||||
std::string connect_status_url() const { return m_connect_url + "/slicer/status"; }
|
||||
std::string connect_printer_list_url() const { return m_connect_url + "/slicer/printer_list"; }
|
||||
std::string connect_select_printer_url() const { return m_connect_url + "/slicer-select-printer"; }
|
||||
std::string connect_printers_url() const { return m_connect_url + "/app/printers/"; }
|
||||
std::string connect_teams_url() const { return m_connect_url + "/app/teams"; }
|
||||
|
||||
const std::string& account_url() const { return m_account_url; }
|
||||
const std::string& account_client_id() const { return m_account_client_id; }
|
||||
|
||||
std::string account_token_url() const { return m_account_url + "/o/token/"; }
|
||||
std::string account_me_url() const { return m_account_url + "/api/v1/me/"; }
|
||||
std::string account_logout_url() const { return m_account_url + "/logout"; }
|
||||
|
||||
std::string media_url() const { return m_media_url + "/media/"; }
|
||||
|
||||
const std::string& preset_repo_url() const { return m_preset_repo_url; }
|
||||
std::string preset_repo_repos_url() const { return m_preset_repo_url + "/v1/repos"; }
|
||||
|
||||
bool webdev_enabled() const { return m_webdev_enabled; }
|
||||
void set_webdev_enabled(bool enabled) { m_webdev_enabled = enabled; }
|
||||
|
||||
static ServiceConfig& instance();
|
||||
private:
|
||||
std::string m_connect_url;
|
||||
std::string m_account_url;
|
||||
std::string m_account_client_id;
|
||||
std::string m_media_url;
|
||||
std::string m_preset_repo_url;
|
||||
bool m_webdev_enabled{false};
|
||||
};
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user