Allow forwarding JS console of web view to stderr
This commit is contained in:
parent
e43a6c1c98
commit
cdff9fd974
|
@ -90,16 +90,27 @@ use_syncthingconnector()
|
||||||
find_package(syncthingmodel ${META_APP_VERSION} REQUIRED)
|
find_package(syncthingmodel ${META_APP_VERSION} REQUIRED)
|
||||||
use_syncthingmodel()
|
use_syncthingmodel()
|
||||||
|
|
||||||
|
# configure libsyncthing
|
||||||
option(USE_LIBSYNCTHING "whether libsyncthing should be included for the launcher" OFF)
|
option(USE_LIBSYNCTHING "whether libsyncthing should be included for the launcher" OFF)
|
||||||
if(USE_LIBSYNCTHING)
|
if(USE_LIBSYNCTHING)
|
||||||
find_package(syncthing ${META_APP_VERSION} REQUIRED)
|
find_package(syncthing ${META_APP_VERSION} REQUIRED)
|
||||||
use_syncthing()
|
use_syncthing()
|
||||||
set_source_files_properties(
|
set_source_files_properties(
|
||||||
misc/syncthinglauncher.cpp
|
misc/syncthinglauncher.cpp
|
||||||
PROPERTIES COMPILE_DEFINITIONS SYNCTHING_WIDGETS_USE_LIBSYNCTHING
|
PROPERTIES COMPILE_DEFINITIONS SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||||
)
|
)
|
||||||
endif()
|
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
|
# link also explicitely against the following Qt 5 modules
|
||||||
list(APPEND ADDITIONAL_QT_MODULES Network Concurrent)
|
list(APPEND ADDITIONAL_QT_MODULES Network Concurrent)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ SyncthingLauncher::SyncthingLauncher(QObject *parent)
|
||||||
|
|
||||||
bool SyncthingLauncher::isLibSyncthingAvailable()
|
bool SyncthingLauncher::isLibSyncthingAvailable()
|
||||||
{
|
{
|
||||||
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
|
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
|
@ -76,7 +76,7 @@ void SyncthingLauncher::terminate()
|
||||||
m_process.stopSyncthing();
|
m_process.stopSyncthing();
|
||||||
} else if (m_future.isRunning()) {
|
} else if (m_future.isRunning()) {
|
||||||
m_manuallyStopped = true;
|
m_manuallyStopped = true;
|
||||||
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
|
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||||
LibSyncthing::stopSyncthing();
|
LibSyncthing::stopSyncthing();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ void SyncthingLauncher::kill()
|
||||||
m_process.stopSyncthing();
|
m_process.stopSyncthing();
|
||||||
} else if (m_future.isRunning()) {
|
} else if (m_future.isRunning()) {
|
||||||
m_manuallyStopped = true;
|
m_manuallyStopped = true;
|
||||||
#ifdef SYNCTHING_WIDGETS_USE_LIBSYNCTHING
|
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||||
// FIXME: any change to try harder?
|
// FIXME: any change to try harder?
|
||||||
LibSyncthing::stopSyncthing();
|
LibSyncthing::stopSyncthing();
|
||||||
#endif
|
#endif
|
||||||
|
@ -117,7 +117,7 @@ static const char *const logLevelStrings[] = {
|
||||||
|
|
||||||
void SyncthingLauncher::handleLoggingCallback(LibSyncthing::LogLevel level, const char *message, size_t messageSize)
|
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) {
|
if (level < LibSyncthing::LogLevel::Info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ void SyncthingLauncher::handleLoggingCallback(LibSyncthing::LogLevel level, cons
|
||||||
|
|
||||||
void SyncthingLauncher::runLibSyncthing(const LibSyncthing::RuntimeOptions &runtimeOptions)
|
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));
|
LibSyncthing::setLoggingCallback(bind(&SyncthingLauncher::handleLoggingCallback, this, _1, _2, _3));
|
||||||
const auto exitCode = LibSyncthing::runSyncthing(runtimeOptions);
|
const auto exitCode = LibSyncthing::runSyncthing(runtimeOptions);
|
||||||
emit exited(static_cast<int>(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit);
|
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)
|
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));
|
LibSyncthing::setLoggingCallback(bind(&SyncthingLauncher::handleLoggingCallback, this, _1, _2, _3));
|
||||||
const auto exitCode = LibSyncthing::runSyncthing(arguments);
|
const auto exitCode = LibSyncthing::runSyncthing(arguments);
|
||||||
emit exited(static_cast<int>(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit);
|
emit exited(static_cast<int>(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit);
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
#include <QWebView>
|
#include <QWebView>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SYNCTHINGWIDGETS_LOG_JAVASCRIPT_CONSOLE
|
||||||
|
#include <iostream>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Data;
|
using namespace Data;
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
@ -260,6 +264,9 @@ void WebPage::injectJavaScripts(bool ok)
|
||||||
*/
|
*/
|
||||||
void WebPage::processJavaScriptConsoleMessage(const QString &message)
|
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: "))) {
|
if (message.startsWith(QLatin1String("nativeInterface.showFolderPathSelection: "))) {
|
||||||
showFolderPathSelection(message.mid(41));
|
showFolderPathSelection(message.mid(41));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue