Allow forwarding JS console of web view to stderr

This commit is contained in:
Martchus 2018-10-28 17:03:23 +01:00
parent e43a6c1c98
commit cdff9fd974
3 changed files with 25 additions and 7 deletions

View File

@ -90,16 +90,27 @@ use_syncthingconnector()
find_package(syncthingmodel ${META_APP_VERSION} REQUIRED)
use_syncthingmodel()
# configure libsyncthing
option(USE_LIBSYNCTHING "whether libsyncthing should be included for the launcher" OFF)
if(USE_LIBSYNCTHING)
find_package(syncthing ${META_APP_VERSION} REQUIRED)
use_syncthing()
set_source_files_properties(
misc/syncthinglauncher.cpp
PROPERTIES COMPILE_DEFINITIONS SYNCTHING_WIDGETS_USE_LIBSYNCTHING
PROPERTIES COMPILE_DEFINITIONS SYNCTHINGWIDGETS_USE_LIBSYNCTHING
)
endif()
# configure logging JavaScript events to stderr
option(SYNCTHING_WIDGETS_LOG_JAVASCRIPT_CONSOLE "enables logging JavaScript events of webview to stderr" OFF)
if(SYNCTHING_WIDGETS_LOG_JAVASCRIPT_CONSOLE)
set_property(
SOURCE webview/webpage.cpp
APPEND PROPERTY COMPILE_DEFINITIONS SYNCTHINGWIDGETS_LOG_JAVASCRIPT_CONSOLE
)
message(WARNING "JavaScript console of web view will be logged to stderr")
endif()
# link also explicitely against the following Qt 5 modules
list(APPEND ADDITIONAL_QT_MODULES Network Concurrent)

View File

@ -25,7 +25,7 @@ SyncthingLauncher::SyncthingLauncher(QObject *parent)
bool SyncthingLauncher::isLibSyncthingAvailable()
{
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
return true;
#else
return false;
@ -76,7 +76,7 @@ void SyncthingLauncher::terminate()
m_process.stopSyncthing();
} else if (m_future.isRunning()) {
m_manuallyStopped = true;
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
LibSyncthing::stopSyncthing();
#endif
}
@ -89,7 +89,7 @@ void SyncthingLauncher::kill()
m_process.stopSyncthing();
} else if (m_future.isRunning()) {
m_manuallyStopped = true;
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
// FIXME: any change to try harder?
LibSyncthing::stopSyncthing();
#endif
@ -117,7 +117,7 @@ static const char *const logLevelStrings[] = {
void SyncthingLauncher::handleLoggingCallback(LibSyncthing::LogLevel level, const char *message, size_t messageSize)
{
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
if (level < LibSyncthing::LogLevel::Info) {
return;
}
@ -138,7 +138,7 @@ void SyncthingLauncher::handleLoggingCallback(LibSyncthing::LogLevel level, cons
void SyncthingLauncher::runLibSyncthing(const LibSyncthing::RuntimeOptions &runtimeOptions)
{
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
LibSyncthing::setLoggingCallback(bind(&SyncthingLauncher::handleLoggingCallback, this, _1, _2, _3));
const auto exitCode = LibSyncthing::runSyncthing(runtimeOptions);
emit exited(static_cast<int>(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit);
@ -151,7 +151,7 @@ void SyncthingLauncher::runLibSyncthing(const LibSyncthing::RuntimeOptions &runt
void SyncthingLauncher::runLibSyncthing(const std::vector<string> &arguments)
{
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
LibSyncthing::setLoggingCallback(bind(&SyncthingLauncher::handleLoggingCallback, this, _1, _2, _3));
const auto exitCode = LibSyncthing::runSyncthing(arguments);
emit exited(static_cast<int>(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit);

View File

@ -26,6 +26,10 @@
#include <QWebView>
#endif
#ifdef SYNCTHINGWIDGETS_LOG_JAVASCRIPT_CONSOLE
#include <iostream>
#endif
using namespace Data;
namespace QtGui {
@ -260,6 +264,9 @@ void WebPage::injectJavaScripts(bool ok)
*/
void WebPage::processJavaScriptConsoleMessage(const QString &message)
{
#ifdef SYNCTHINGWIDGETS_LOG_JAVASCRIPT_CONSOLE
std::cerr << "JS console: " << message.toLocal8Bit().data() << std::endl;
#endif
if (message.startsWith(QLatin1String("nativeInterface.showFolderPathSelection: "))) {
showFolderPathSelection(message.mid(41));
}