mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-02 20:28:14 +02:00
Support legacy collection api
This commit is contained in:
@@ -622,9 +622,11 @@ Tomahawk.PluginManager = {
|
|||||||
Tomahawk.unregisterScriptPlugin(type, object.id);
|
Tomahawk.unregisterScriptPlugin(type, object.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
invokeSync: function (objectId, methodName, params) {
|
resolve: [],
|
||||||
|
invokeSync: function (requestId, objectId, methodName, params) {
|
||||||
|
var pluginManager = this;
|
||||||
if (!this.objects[objectId]) {
|
if (!this.objects[objectId]) {
|
||||||
Tomahawk.log("Object not found!");
|
Tomahawk.log("Object not found! objectId: " + objectId + " methodName: " + methodName);
|
||||||
} else {
|
} else {
|
||||||
if (!this.objects[objectId][methodName]) {
|
if (!this.objects[objectId][methodName]) {
|
||||||
Tomahawk.log("Function not found: " + methodName);
|
Tomahawk.log("Function not found: " + methodName);
|
||||||
@@ -632,6 +634,25 @@ Tomahawk.PluginManager = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof this.objects[objectId][methodName] === 'function') {
|
if (typeof this.objects[objectId][methodName] === 'function') {
|
||||||
|
if (!Tomahawk.resolver.instance.apiVersion || Tomahawk.resolver.instance.apiVersion < 0.9) {
|
||||||
|
if (methodName == 'artists') {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
pluginManager.resolve[requestId] = resolve;
|
||||||
|
Tomahawk.resolver.instance.artists(requestId);
|
||||||
|
});
|
||||||
|
} else if (methodName == 'albums') {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
pluginManager.resolve[requestId] = resolve;
|
||||||
|
Tomahawk.resolver.instance.albums(requestId, params.artist);
|
||||||
|
});
|
||||||
|
} else if (methodName == 'tracks') {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
pluginManager.resolve[requestId] = resolve;
|
||||||
|
Tomahawk.resolver.instance.tracks(requestId, params.artist, params.album);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this.objects[objectId][methodName](params);
|
return this.objects[objectId][methodName](params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,7 +660,7 @@ Tomahawk.PluginManager = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
invoke: function (requestId, objectId, methodName, params ) {
|
invoke: function (requestId, objectId, methodName, params ) {
|
||||||
Promise.resolve(this.invokeSync(objectId, methodName, params)).then(function (result) {
|
Promise.resolve(this.invokeSync(requestId, objectId, methodName, params)).then(function (result) {
|
||||||
if (typeof result === 'object') {
|
if (typeof result === 'object') {
|
||||||
Tomahawk.reportScriptJobResults({
|
Tomahawk.reportScriptJobResults({
|
||||||
requestId: requestId,
|
requestId: requestId,
|
||||||
@@ -671,3 +692,17 @@ Tomahawk.ConfigTestResultType = {
|
|||||||
PlayingElsewhere: 6,
|
PlayingElsewhere: 6,
|
||||||
AccountExpired: 7
|
AccountExpired: 7
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Legacy compability for 0.8 and before
|
||||||
|
Tomahawk.reportCapabilities = function (capabilities) {
|
||||||
|
if (capabilities & TomahawkResolverCapability.Browsable) {
|
||||||
|
Tomahawk.PluginManager.registerPlugin("collection", Tomahawk.resolver.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk.nativeReportCapabilities(capabilities);
|
||||||
|
};
|
||||||
|
|
||||||
|
Tomahawk.addArtistResults = Tomahawk.addAlbumResults = Tomahawk.addAlbumTrackResults = function (result) {
|
||||||
|
Tomahawk.PluginManager.resolve[result.qid](result);
|
||||||
|
};
|
||||||
|
@@ -155,6 +155,7 @@ JSAccount::syncInvoke( const scriptobject_ptr& scriptObject, const QString& meth
|
|||||||
{
|
{
|
||||||
QString eval = QString(
|
QString eval = QString(
|
||||||
"Tomahawk.PluginManager.invokeSync("
|
"Tomahawk.PluginManager.invokeSync("
|
||||||
|
"0, " // requestId
|
||||||
"'%1'," // objectId
|
"'%1'," // objectId
|
||||||
"'%2'," // methodName
|
"'%2'," // methodName
|
||||||
"%3" // arguments
|
"%3" // arguments
|
||||||
|
@@ -308,7 +308,7 @@ JSResolverHelper::addUrlResult( const QString& url, const QVariantMap& result )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
JSResolverHelper::reportCapabilities( const QVariant& v )
|
JSResolverHelper::nativeReportCapabilities( const QVariant& v )
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
int intCap = v.toInt( &ok );
|
int intCap = v.toInt( &ok );
|
||||||
|
@@ -145,7 +145,7 @@ public slots:
|
|||||||
|
|
||||||
void addUrlResult( const QString& url, const QVariantMap& result );
|
void addUrlResult( const QString& url, const QVariantMap& result );
|
||||||
|
|
||||||
void reportCapabilities( const QVariant& capabilities );
|
void nativeReportCapabilities( const QVariant& capabilities );
|
||||||
|
|
||||||
void reportScriptJobResults( const QVariantMap& result );
|
void reportScriptJobResults( const QVariantMap& result );
|
||||||
|
|
||||||
|
@@ -112,7 +112,7 @@ ScriptCommand_AllTracks::onTracksJobDone( const QVariantMap& result )
|
|||||||
QSharedPointer< ScriptCollection > collection = m_collection.objectCast< ScriptCollection >();
|
QSharedPointer< ScriptCollection > collection = m_collection.objectCast< ScriptCollection >();
|
||||||
Q_ASSERT( !collection.isNull() );
|
Q_ASSERT( !collection.isNull() );
|
||||||
|
|
||||||
QList< Tomahawk::result_ptr > t = collection->scriptAccount()->parseResultVariantList( result[ "tracks"].toList() );
|
QList< Tomahawk::result_ptr > t = collection->scriptAccount()->parseResultVariantList( result[ "results"].toList() );
|
||||||
|
|
||||||
|
|
||||||
QList< Tomahawk::query_ptr > queries;
|
QList< Tomahawk::query_ptr > queries;
|
||||||
|
Reference in New Issue
Block a user