1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 08:52:12 +02:00

Show debugger (WebInspector for JS) when clicking script errors

This commit is contained in:
Dominik Schmidt 2016-02-14 13:50:05 +01:00
parent 942eded60d
commit 2f4eb75745
9 changed files with 115 additions and 16 deletions

@ -37,6 +37,7 @@ set( libGuiSources
jobview/ErrorStatusMessage.cpp
jobview/IndexingJobItem.cpp
jobview/InboxJobItem.cpp
jobview/ScriptErrorStatusMessage.cpp
playlist/InboxModel.cpp
playlist/InboxView.cpp

@ -0,0 +1,37 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2016, Dominik Schmidt <domme@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptErrorStatusMessage.h"
#include "../utils/Logger.h"
ScriptErrorStatusMessage::ScriptErrorStatusMessage( const QString& message, Tomahawk::ScriptAccount* account )
: ErrorStatusMessage( tr( "Script Error: %1" ).arg( message ) )
, m_account( account )
{
}
void
ScriptErrorStatusMessage::activated()
{
if ( m_account.isNull() )
return;
tDebug() << "ScriptErrorStatusMessage clicked: " << mainText() << m_account->name();
m_account->showDebugger();
}

@ -0,0 +1,39 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2016, Dominik Schmidt <domme@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCRIPTERRORSTATUSMESSAGE_H
#define SCRIPTERRORSTATUSMESSAGE_H
#include "ErrorStatusMessage.h"
#include "../resolvers/ScriptAccount.h"
#include "DllMacro.h"
class DLLEXPORT ScriptErrorStatusMessage : public ErrorStatusMessage
{
Q_OBJECT
public:
explicit ScriptErrorStatusMessage( const QString& scriptErrorMessage, Tomahawk::ScriptAccount* );
void activated() override;
private:
QPointer< Tomahawk::ScriptAccount > m_account;
};
#endif // SCRIPTERRORSTATUSMESSAGE_H

@ -67,6 +67,14 @@ JSAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr& obj
}
void
JSAccount::showDebugger()
{
tLog() << Q_FUNC_INFO << name() << "Show debugger";
m_engine->showWebInspector();
}
QString
JSAccount::serializeQVariantMap( const QVariantMap& map )
{

@ -69,6 +69,8 @@ public:
void setResolver( JSResolver* resolver );
void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ) override;
void showDebugger() override;
static QString serializeQVariantMap(const QVariantMap& map);
void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override;

@ -255,6 +255,12 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr&
}
void
ScriptAccount::showDebugger()
{
}
void
ScriptAccount::onJobDeleted( const QString& jobId )
{

@ -76,6 +76,8 @@ public:
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
virtual void showDebugger();
// helpers
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );

@ -21,7 +21,7 @@
#include "ScriptEngine.h"
#include "jobview/ErrorStatusMessage.h"
#include "jobview/ScriptErrorStatusMessage.h"
#include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h"
#include "utils/Logger.h"
@ -51,13 +51,13 @@ ScriptEngine::ScriptEngine( JSAccount* parent )
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
settings()->setOfflineStorageDefaultQuota(100 * 1024 * 1024 /* 100 Mb */);
settings()->setOfflineWebApplicationCacheQuota(100 * 1024 * 1024 /* 100 Mb */);
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
// HACK
QStringList cmdArgs = QCoreApplication::instance()->arguments();
int position = cmdArgs.indexOf( "--show-inspector" ) + 1;
if ( position > 0 && !cmdArgs.at( position ).isEmpty() && parent->name().contains( cmdArgs.at( position ), Qt::CaseInsensitive ) ) {
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
QMetaObject::invokeMethod( this, "initWebInspector", Qt::QueuedConnection );
QMetaObject::invokeMethod( this, "showWebInspector", Qt::QueuedConnection );
}
// Tomahawk is not a user agent
@ -74,24 +74,13 @@ ScriptEngine::ScriptEngine( JSAccount* parent )
}
void
ScriptEngine::initWebInspector()
{
m_webInspector.reset( new QWebInspector() );
m_webInspector->setPage( this );
m_webInspector->setMinimumWidth( 800 );
m_webInspector->setMinimumHeight( 600 );
m_webInspector->show();
}
void
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
{
tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID;
#ifdef QT_DEBUG
QFileInfo scriptPath( m_scriptPath );
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Resolver Error: %1:%2 %3" ).arg( scriptPath.fileName() ).arg( lineNumber ).arg( message ) ) );
JobStatusView::instance()->model()->addJob( new ScriptErrorStatusMessage( tr( "%1:%2 %3" ).arg( scriptPath.fileName() ).arg( lineNumber ).arg( message ), m_parent ) );
#endif
}
@ -148,6 +137,21 @@ ScriptEngine::setScriptPath( const QString& scriptPath )
}
void
ScriptEngine::showWebInspector()
{
if ( m_webInspector.isNull() )
{
m_webInspector.reset( new QWebInspector() );
m_webInspector->setPage( this );
m_webInspector->setMinimumWidth( 800 );
m_webInspector->setMinimumHeight( 600 );
}
m_webInspector->show();
}
bool
ScriptEngine::shouldInterruptJavaScript()
{

@ -49,13 +49,13 @@ public:
public slots:
bool shouldInterruptJavaScript();
void showWebInspector();
protected:
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
private slots:
void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist );
void initWebInspector();
private:
JSAccount* m_parent;