Skip to content

Commit

Permalink
add test url dialog for flutter debug
Browse files Browse the repository at this point in the history
  • Loading branch information
womendoushihaoyin committed Jan 18, 2025
1 parent 50ea79a commit f20ab14
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/web/homepage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<div board="device" style="display:none">
<div id="DeviceTitleBlock">
<div id="DeviceTitle" class="Content-Title trans TextS1" tid="device_title">设备管理</div>
<div id="DeviceTitle" class="Content-Title trans TextS1" tid="t114" onClick="onDeviceManagementClick(event)">Device Management</div>
</div>
<div id="DeviceList">
<img class="DeviceAddIcon" src="img/plus.png" alt="添加设备" onClick="OnAddDevice()"/>
Expand Down
34 changes: 34 additions & 0 deletions resources/web/homepage/js/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//var TestData={"sequence_id":"0","command":"get_recent_projects","response":[{"path":"D:\\work\\Models\\Toy\\3d-puzzle-cube-model_files\\3d-puzzle-cube.3mf","time":"2022\/3\/24 20:33:10"},{"path":"D:\\work\\Models\\Art\\Carved Stone Vase - remeshed+drainage\\Carved Stone Vase.3mf","time":"2022\/3\/24 17:11:51"},{"path":"D:\\work\\Models\\Art\\Kity & Cat\\Cat.3mf","time":"2022\/3\/24 17:07:55"},{"path":"D:\\work\\Models\\Toy\\鐩村墤.3mf","time":"2022\/3\/24 17:06:02"},{"path":"D:\\work\\Models\\Toy\\minimalistic-dual-tone-whistle-model_files\\minimalistic-dual-tone-whistle.3mf","time":"2022\/3\/22 21:12:22"},{"path":"D:\\work\\Models\\Toy\\spiral-city-model_files\\spiral-city.3mf","time":"2022\/3\/22 18:58:37"},{"path":"D:\\work\\Models\\Toy\\impossible-dovetail-puzzle-box-model_files\\impossible-dovetail-puzzle-box.3mf","time":"2022\/3\/22 20:08:40"}]};

var m_HotModelList=null;
var deviceClickCount = 0;
var deviceClickTimer = null;

function OnInit()
{
Expand Down Expand Up @@ -511,6 +513,38 @@ function OnAddDevice() {
SendWXMessage(JSON.stringify(tSend));
}

function OnTestBrowser(){
var tSend = {};
tSend['sequence_id'] = Math.round(new Date() / 1000);
tSend['command'] = "homepage_test_browser";

SendWXMessage(JSON.stringify(tSend));
}

//---------------Global-----------------
window.postMessage = HandleStudio;

function onDeviceManagementClick(e) {
// 阻止事件冒泡,避免触发菜单切换
e.stopPropagation();

deviceClickCount++;

// 清除之前的定时器
if (deviceClickTimer) {
clearTimeout(deviceClickTimer);
}

// 设置新的定时器,1秒后重置点击次数
deviceClickTimer = setTimeout(() => {
deviceClickCount = 0;
}, 1000);

// 检查是否达到三次点击
if (deviceClickCount >= 3) {
deviceClickCount = 0;
clearTimeout(deviceClickTimer);
OnTestBrowser();
}
}

2 changes: 2 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ set(SLIC3R_GUI_SOURCES
GUI/WebSMUserLoginDialog.hpp
GUI/WebDeviceDialog.cpp
GUI/WebDeviceDialog.hpp
GUI/WebUrlDialog.cpp
GUI/WebUrlDialog.hpp
GUI/ConfigManipulation.cpp
GUI/ConfigManipulation.hpp
GUI/Field.cpp
Expand Down
10 changes: 10 additions & 0 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "libslic3r_version.h"
#include "Downloader.hpp"

#include "slic3r/GUI/WebUrlDialog.hpp"

// Localization headers: include libslic3r version first so everything in this file
// uses the slic3r/GUI version (the macros will take precedence over the functions).
// Also, there is a check that the former is not included from slic3r module.
Expand Down Expand Up @@ -4018,6 +4020,14 @@ std::string GUI_App::handle_web_request(std::string cmd)
});
return "";
}
else if (command_str.compare("homepage_test_browser") == 0) {
CallAfter([this] {
auto dialog = new WebUrlDialog();
dialog->load_url("https://www.baidu.com");
dialog->ShowModal();
delete dialog;
});
}
}
}
catch (...) {
Expand Down
132 changes: 132 additions & 0 deletions src/slic3r/GUI/WebUrlDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// WebUrlDialog.cpp
#include "WebUrlDialog.hpp"
#include "I18N.hpp"
#include "GUI_App.hpp"
#include "MainFrame.hpp"
#include "SSWCP.hpp"
#include <wx/sizer.h>
#include <slic3r/GUI/Widgets/WebView.hpp>

namespace Slic3r { namespace GUI {

BEGIN_EVENT_TABLE(WebUrlDialog, wxDialog)
EVT_CLOSE(WebUrlDialog::OnClose)
END_EVENT_TABLE()

WebUrlDialog::WebUrlDialog()
: wxDialog((wxWindow*)(wxGetApp().mainframe), wxID_ANY, _L("Web View"))
{
SetBackgroundColour(*wxWHITE);

// 创建顶部输入区域
auto *top_sizer = new wxBoxSizer(wxHORIZONTAL);
m_url_input = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, FromDIP(wxSize(300, -1)));
m_load_button = new wxButton(this, wxID_ANY, _L("Load"));

top_sizer->Add(m_url_input, 1, wxEXPAND | wxALL, 5);
top_sizer->Add(m_load_button, 0, wxALL, 5);

// 创建WebView
m_browser = WebView::CreateWebView(this, "about:blank");
if (m_browser == nullptr) {
wxLogError("Could not init m_browser");
return;
}
m_browser->Hide();

// 绑定事件
Bind(wxEVT_WEBVIEW_NAVIGATING, &WebUrlDialog::OnNavigationRequest, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_NAVIGATED, &WebUrlDialog::OnNavigationComplete, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_LOADED, &WebUrlDialog::OnDocumentLoaded, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_ERROR, &WebUrlDialog::OnError, this, m_browser->GetId());
Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &WebUrlDialog::OnScriptMessage, this, m_browser->GetId());
m_load_button->Bind(wxEVT_BUTTON, &WebUrlDialog::OnLoadUrl, this);

// 设置主布局
auto *main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(top_sizer, 0, wxEXPAND);
main_sizer->Add(m_browser, 1, wxEXPAND);

SetSizer(main_sizer);
SetSize(FromDIP(wxSize(800, 600)));
CenterOnParent();

wxGetApp().UpdateDlgDarkUI(this);
}

WebUrlDialog::~WebUrlDialog()
{
SSWCP::on_webview_delete(m_browser);
}

void WebUrlDialog::load_url(const wxString &url)
{
m_url_input->SetValue(url);
m_browser->LoadURL(url);
m_browser->Show();
Layout();
}

void WebUrlDialog::OnLoadUrl(wxCommandEvent& evt)
{
wxString url = m_url_input->GetValue();
if (!url.IsEmpty()) {
load_url(url);
}
}

bool WebUrlDialog::run()
{
if (this->ShowModal() == wxID_OK) {
return true;
}
return false;
}

void WebUrlDialog::RunScript(const wxString &javascript)
{
m_javascript = javascript;
if (!m_browser) return;
WebView::RunScript(m_browser, javascript);
}

void WebUrlDialog::OnNavigationRequest(wxWebViewEvent &evt)
{
evt.Skip();
}

void WebUrlDialog::OnNavigationComplete(wxWebViewEvent &evt)
{
m_browser->Show();
Layout();
}

void WebUrlDialog::OnDocumentLoaded(wxWebViewEvent &evt)
{
evt.Skip();
}

void WebUrlDialog::OnError(wxWebViewEvent &evt)
{
wxLogError("Web View Error: %s", evt.GetString());
}

void WebUrlDialog::OnScriptMessage(wxWebViewEvent &evt)
{
BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << ": " << evt.GetString().ToUTF8().data();

if (wxGetApp().get_mode() == comDevelop)
wxLogMessage("Script message received; value = %s, handler = %s",
evt.GetString(), evt.GetMessageHandler());

// 处理SSWCP消息
SSWCP::handle_web_message(evt.GetString().ToUTF8().data(), m_browser);
}

void WebUrlDialog::OnClose(wxCloseEvent& evt)
{
evt.Skip();
}

}} // namespace Slic3r::GUI
43 changes: 43 additions & 0 deletions src/slic3r/GUI/WebUrlDialog.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

// WebUrlDialog.hpp
#ifndef slic3r_WebUrlDialog_hpp_
#define slic3r_WebUrlDialog_hpp_

#include <wx/dialog.h>
#include <wx/webview.h>
#include <wx/timer.h>
#include <wx/textctrl.h>
#include <wx/button.h>

namespace Slic3r { namespace GUI {

class WebUrlDialog : public wxDialog
{
public:
WebUrlDialog();
virtual ~WebUrlDialog();

void load_url(const wxString &url);
bool run();
void RunScript(const wxString &javascript);

private:
void OnClose(wxCloseEvent& evt);
void OnNavigationRequest(wxWebViewEvent &evt);
void OnNavigationComplete(wxWebViewEvent &evt);
void OnDocumentLoaded(wxWebViewEvent &evt);
void OnError(wxWebViewEvent &evt);
void OnScriptMessage(wxWebViewEvent &evt);
void OnLoadUrl(wxCommandEvent& evt);

wxWebView* m_browser{nullptr};
wxTextCtrl* m_url_input{nullptr};
wxButton* m_load_button{nullptr};
wxString m_javascript;

DECLARE_EVENT_TABLE()
};

}} // namespace Slic3r::GUI

#endif

0 comments on commit f20ab14

Please sign in to comment.