Skip to content

Commit

Permalink
Suppress QWebEngineContext info, suppress JS console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbreeze413 committed Jan 25, 2024
1 parent ea4c5d5 commit de2e713
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/MainWindow/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDialogButtonBox>
#include <QLabel>
#include <QListView>
#include <QLoggingCategory>
#include <QMenuBar>
#include <QMessageBox>
#include <QProgressBar>
Expand Down Expand Up @@ -138,6 +139,9 @@ MainWindow::MainWindow(Session* session)
it after some time (in post showEvent period), since it doesn't play any
specific role, except the role of having it for initialization.
*/
// https://doc.qt.io/qt-6/qloggingcategory.html#configuring-categories
// https://stackoverflow.com/questions/74499940/how-to-disable-qwebengineview-logging-with-webenginecontextlog
QLoggingCategory::setFilterRules("qt.webenginecontext.info=false");
QWebEngineView* preloadWebView = new QWebEngineView(this);
preloadWebView->resize(0, 0);
QTimer::singleShot(1, [preloadWebView]() { preloadWebView->deleteLater(); });
Expand Down
4 changes: 2 additions & 2 deletions src/TextEditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set (SRC_CPP_LIST
text_editor.cpp
text_editor_form.cpp)
if (USE_MONACO_EDITOR)
list(APPEND SRC_CPP_LIST monaco_editor.cpp cpp_endpoint.cpp)
list(APPEND SRC_CPP_LIST monaco_editor_page.cpp monaco_editor.cpp cpp_endpoint.cpp)
else()
list(APPEND SRC_CPP_LIST search_dialog.cpp editor.cpp)
endif()
Expand All @@ -34,7 +34,7 @@ set (SRC_H_LIST
text_editor.h
text_editor_form.h)
if (USE_MONACO_EDITOR)
list(APPEND SRC_H_LIST monaco_editor.h cpp_endpoint.h)
list(APPEND SRC_H_LIST monaco_editor_page.h monaco_editor.h cpp_endpoint.h)
else()
list(APPEND SRC_H_LIST search_dialog.h editor.h)
endif()
Expand Down
4 changes: 4 additions & 0 deletions src/TextEditor/monaco_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Main/ToolContext.h"
#include "MainWindow/Session.h"
#include "cpp_endpoint.h"
#include "monaco_editor_page.h"

extern FOEDAG::Session* GlobalSession;

Expand Down Expand Up @@ -60,6 +61,9 @@ Editor::Editor(QString strFileName, int iFileType, QWidget* parent)
// init it with the filepath to be opened
m_CPPEndPointObject = new CPPEndPoint(this, m_strFileName);

m_webEngineViewPage = new MonacoEditorPage();
m_webEngineView->setPage(m_webEngineViewPage);

m_webEngineView->page()->settings()->setAttribute(
QWebEngineSettings::LocalContentCanAccessFileUrls, true);
// ref:
Expand Down
2 changes: 2 additions & 0 deletions src/TextEditor/monaco_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QVBoxLayout;
class QWebEngineView;
class QWebChannel;
class CPPEndPoint;
class MonacoEditorPage;

namespace FOEDAG {

Expand Down Expand Up @@ -61,6 +62,7 @@ class Editor : public QWidget {
bool m_closeAfterSave;
QString m_strFileName;
QWebEngineView* m_webEngineView;
MonacoEditorPage* m_webEngineViewPage;
QWebChannel* m_webEngineChannel;
CPPEndPoint* m_CPPEndPointObject;

Expand Down
13 changes: 13 additions & 0 deletions src/TextEditor/monaco_editor_page.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#include "monaco_editor_page.h"

#include <QWebEnginePage>

MonacoEditorPage::MonacoEditorPage(QObject *parent) : QWebEnginePage(parent) {}

void MonacoEditorPage::javaScriptConsoleMessage(
JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber,
const QString &sourceID) {
// do nothing, all messages from JS console are suppressed!
// qDebug() << message;
}
15 changes: 15 additions & 0 deletions src/TextEditor/monaco_editor_page.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef MONACO_EDITOR_PAGE_H
#define MONACO_EDITOR_PAGE_H

#include <QWebEnginePage>

class MonacoEditorPage : public QWebEnginePage {
Q_OBJECT
public:
MonacoEditorPage(QObject *parent = 0);
virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
const QString &message, int lineNumber,
const QString &sourceID);
};

#endif // MONACO_EDITOR_PAGE_H

0 comments on commit de2e713

Please sign in to comment.