mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Show debugger (WebInspector for JS) when clicking script errors
This commit is contained in:
@@ -37,6 +37,7 @@ set( libGuiSources
|
|||||||
jobview/ErrorStatusMessage.cpp
|
jobview/ErrorStatusMessage.cpp
|
||||||
jobview/IndexingJobItem.cpp
|
jobview/IndexingJobItem.cpp
|
||||||
jobview/InboxJobItem.cpp
|
jobview/InboxJobItem.cpp
|
||||||
|
jobview/ScriptErrorStatusMessage.cpp
|
||||||
|
|
||||||
playlist/InboxModel.cpp
|
playlist/InboxModel.cpp
|
||||||
playlist/InboxView.cpp
|
playlist/InboxView.cpp
|
||||||
|
37
src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp
Normal file
37
src/libtomahawk/jobview/ScriptErrorStatusMessage.cpp
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
|
39
src/libtomahawk/jobview/ScriptErrorStatusMessage.h
Normal file
39
src/libtomahawk/jobview/ScriptErrorStatusMessage.h
Normal file
@@ -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
|
QString
|
||||||
JSAccount::serializeQVariantMap( const QVariantMap& map )
|
JSAccount::serializeQVariantMap( const QVariantMap& map )
|
||||||
{
|
{
|
||||||
|
@@ -69,6 +69,8 @@ public:
|
|||||||
void setResolver( JSResolver* resolver );
|
void setResolver( JSResolver* resolver );
|
||||||
void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ) override;
|
void scriptPluginFactory( const QString& type, const scriptobject_ptr& object ) override;
|
||||||
|
|
||||||
|
void showDebugger() override;
|
||||||
|
|
||||||
static QString serializeQVariantMap(const QVariantMap& map);
|
static QString serializeQVariantMap(const QVariantMap& map);
|
||||||
|
|
||||||
void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override;
|
void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override;
|
||||||
|
@@ -255,6 +255,12 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr&
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptAccount::showDebugger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScriptAccount::onJobDeleted( const QString& jobId )
|
ScriptAccount::onJobDeleted( const QString& jobId )
|
||||||
{
|
{
|
||||||
|
@@ -76,6 +76,8 @@ public:
|
|||||||
|
|
||||||
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
|
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
|
||||||
|
|
||||||
|
virtual void showDebugger();
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
||||||
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );
|
ScriptJob* resolve( const scriptobject_ptr& scriptObject, const query_ptr& query, const QString& resolveType );
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "ScriptEngine.h"
|
#include "ScriptEngine.h"
|
||||||
|
|
||||||
#include "jobview/ErrorStatusMessage.h"
|
#include "jobview/ScriptErrorStatusMessage.h"
|
||||||
#include "jobview/JobStatusModel.h"
|
#include "jobview/JobStatusModel.h"
|
||||||
#include "jobview/JobStatusView.h"
|
#include "jobview/JobStatusView.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@@ -51,13 +51,13 @@ ScriptEngine::ScriptEngine( JSAccount* parent )
|
|||||||
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
|
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
|
||||||
settings()->setOfflineStorageDefaultQuota(100 * 1024 * 1024 /* 100 Mb */);
|
settings()->setOfflineStorageDefaultQuota(100 * 1024 * 1024 /* 100 Mb */);
|
||||||
settings()->setOfflineWebApplicationCacheQuota(100 * 1024 * 1024 /* 100 Mb */);
|
settings()->setOfflineWebApplicationCacheQuota(100 * 1024 * 1024 /* 100 Mb */);
|
||||||
|
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
|
||||||
|
|
||||||
// HACK
|
// HACK
|
||||||
QStringList cmdArgs = QCoreApplication::instance()->arguments();
|
QStringList cmdArgs = QCoreApplication::instance()->arguments();
|
||||||
int position = cmdArgs.indexOf( "--show-inspector" ) + 1;
|
int position = cmdArgs.indexOf( "--show-inspector" ) + 1;
|
||||||
if ( position > 0 && !cmdArgs.at( position ).isEmpty() && parent->name().contains( cmdArgs.at( position ), Qt::CaseInsensitive ) ) {
|
if ( position > 0 && !cmdArgs.at( position ).isEmpty() && parent->name().contains( cmdArgs.at( position ), Qt::CaseInsensitive ) ) {
|
||||||
settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
|
QMetaObject::invokeMethod( this, "showWebInspector", Qt::QueuedConnection );
|
||||||
QMetaObject::invokeMethod( this, "initWebInspector", Qt::QueuedConnection );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tomahawk is not a user agent
|
// 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
|
void
|
||||||
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
|
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
|
||||||
{
|
{
|
||||||
tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID;
|
tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID;
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
QFileInfo scriptPath( m_scriptPath );
|
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
|
#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
|
bool
|
||||||
ScriptEngine::shouldInterruptJavaScript()
|
ScriptEngine::shouldInterruptJavaScript()
|
||||||
{
|
{
|
||||||
|
@@ -49,13 +49,13 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool shouldInterruptJavaScript();
|
bool shouldInterruptJavaScript();
|
||||||
|
void showWebInspector();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
|
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist );
|
void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist );
|
||||||
void initWebInspector();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JSAccount* m_parent;
|
JSAccount* m_parent;
|
||||||
|
Reference in New Issue
Block a user