diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index 65681dbe2..f7a319411 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -594,7 +594,7 @@ Tomahawk.base64Encode = function(b) { return window.btoa(b); }; Tomahawk.PluginManager = { objects: {}, identifyObject: function (object) { - if( object.id === undefined ) { + if( !object.hasOwnProperty('id') ) { object.id = Tomahawk.uuid(); } @@ -612,7 +612,7 @@ Tomahawk.PluginManager = { requestId: requestId, data: result }); - },function (error) { + }, function (error) { Tomahawk.reportScriptJobResults({error: error}); }); } diff --git a/src/libtomahawk/resolvers/JSPlugin.cpp b/src/libtomahawk/resolvers/JSPlugin.cpp index c3b233ea9..0924a09ab 100644 --- a/src/libtomahawk/resolvers/JSPlugin.cpp +++ b/src/libtomahawk/resolvers/JSPlugin.cpp @@ -120,7 +120,8 @@ JSPlugin::startJob( ScriptJob* scriptJob ) .arg( scriptJob->methodName() ) .arg( serializeQVariantMap( scriptJob->arguments() ) ); - tLog() << Q_FUNC_INFO << eval; + // Remove when new scripting api turned out to work reliably + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << eval; evaluateJavaScript( eval ); } diff --git a/src/libtomahawk/resolvers/JSPlugin.h b/src/libtomahawk/resolvers/JSPlugin.h index 263c59a9e..a025c02d7 100644 --- a/src/libtomahawk/resolvers/JSPlugin.h +++ b/src/libtomahawk/resolvers/JSPlugin.h @@ -48,18 +48,18 @@ public: const QString name() const; /** - * Evaluate JavaScript on the WebKit thread - */ + * Evaluate JavaScript on the WebKit thread + */ Q_INVOKABLE void evaluateJavaScript( const QString& scriptSource ); /** - * This method must be called from the WebKit thread - */ + * This method must be called from the WebKit thread + */ QVariant evaluateJavaScriptWithResult( const QString& scriptSource ); /** - * Escape \ and ' in strings so they are safe to use in JavaScript - */ + * Escape \ and ' in strings so they are safe to use in JavaScript + */ static QString escape( const QString& source ); diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index 9dcb3d678..5c46102ca 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -65,7 +65,7 @@ JSResolver::JSResolver( const QString& accountId, const QString& scriptPath, con tLog() << Q_FUNC_INFO << "Loading JS resolver:" << scriptPath; d->name = QFileInfo( filePath() ).baseName(); - d->scriptPlugin = new JSPlugin( d->name ); + d->scriptPlugin.reset( new JSPlugin( d->name ) ); // set the icon, if we launch properly we'll get the icon the resolver reports d->icon = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultResolver, TomahawkUtils::Original, QSize( 128, 128 ) ); @@ -87,8 +87,6 @@ JSResolver::~JSResolver() Q_D( JSResolver ); if ( !d->stopped ) stop(); - - delete d->scriptPlugin; } @@ -233,8 +231,10 @@ JSResolver::init() // tomahawk-infosystem.js { + // TODO: be smarter about this, only instantiate this if the resolver supports infoplugins + // add c++ part of tomahawk infosystem bindings as Tomahawk.InfoSystem - d->infoSystemHelper = new JSInfoSystemHelper( d->scriptPlugin ); + d->infoSystemHelper = new JSInfoSystemHelper( d->scriptPlugin.get() ); d->scriptPlugin->addToJavaScriptWindowObject( "_TomahawkInfoSystem", d->infoSystemHelper ); d->scriptPlugin->evaluateJavaScript( "Tomahawk.InfoSystem = _TomahawkInfoSystem;" ); @@ -967,8 +967,6 @@ JSResolver::callOnResolver( const QString& scriptSource ) QString propertyName = scriptSource.split('(').first(); - tLog() << "JAVASCRIPT: run: " << scriptSource; - return d->scriptPlugin->evaluateJavaScriptWithResult( QString( "if(Tomahawk.resolver.instance['_adapter_%1']) {" " Tomahawk.resolver.instance._adapter_%2;" diff --git a/src/libtomahawk/resolvers/JSResolver.h b/src/libtomahawk/resolvers/JSResolver.h index 63dcd8de5..a5ca8e976 100644 --- a/src/libtomahawk/resolvers/JSResolver.h +++ b/src/libtomahawk/resolvers/JSResolver.h @@ -27,8 +27,6 @@ #include "ExternalResolverGui.h" #include "Typedefs.h" - -#include // unique_ptr #include "ScriptEngine.h" // hack, also should be renamed to JSEngine namespace Tomahawk diff --git a/src/libtomahawk/resolvers/JSResolver_p.h b/src/libtomahawk/resolvers/JSResolver_p.h index 0434ce693..0ded52b5b 100644 --- a/src/libtomahawk/resolvers/JSResolver_p.h +++ b/src/libtomahawk/resolvers/JSResolver_p.h @@ -28,6 +28,8 @@ #include "JSInfoSystemHelper.h" #include "database/fuzzyindex/FuzzyIndex.h" +#include // unique_ptr + namespace Tomahawk { @@ -42,7 +44,6 @@ public: , stopped( true ) , error( Tomahawk::ExternalResolver::NoError ) , resolverHelper( new JSResolverHelper( scriptPath, q ) ) - // TODO: be smarter about this, only instantiate this if the resolver supports infoplugins , infoSystemHelper( nullptr ) , requiredScriptPaths( additionalScriptPaths ) { @@ -68,7 +69,7 @@ private: QList< QVariant > dataWidgets; QStringList requiredScriptPaths; - JSPlugin* scriptPlugin; + std::unique_ptr scriptPlugin; }; } // ns: Tomahawk diff --git a/src/libtomahawk/resolvers/ScriptLinkGeneratorPlugin_p.h b/src/libtomahawk/resolvers/ScriptLinkGeneratorPlugin_p.h index fc0840a46..dda1507cd 100644 --- a/src/libtomahawk/resolvers/ScriptLinkGeneratorPlugin_p.h +++ b/src/libtomahawk/resolvers/ScriptLinkGeneratorPlugin_p.h @@ -26,7 +26,6 @@ namespace Tomahawk class ScriptLinkGeneratorPluginPrivate { - friend class ScriptLinkGeneratorPlugin; public: ScriptLinkGeneratorPluginPrivate( ScriptLinkGeneratorPlugin* q, ScriptObject* scriptObject ) : q_ptr ( q ) diff --git a/src/libtomahawk/resolvers/ScriptPlugin.cpp b/src/libtomahawk/resolvers/ScriptPlugin.cpp index a713747eb..5f0faee41 100644 --- a/src/libtomahawk/resolvers/ScriptPlugin.cpp +++ b/src/libtomahawk/resolvers/ScriptPlugin.cpp @@ -31,7 +31,9 @@ using namespace Tomahawk; static QString requestIdGenerator() { - return uuid(); + static int requestCounter = 0; + return QString::number( ++requestCounter ); + }