1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-16 02:54:33 +02:00

Port ScriptInfoPlugin to new generic script plugin infrastructure

This commit is contained in:
Dominik Schmidt
2015-01-05 00:57:13 +01:00
parent 5e5ff7938a
commit 07838afaa6
20 changed files with 167 additions and 404 deletions

View File

@@ -4,7 +4,7 @@ if(window.Promise === undefined) {
}
// TODO: find a way to enumerate TypeInfo instead of copying this manually
Tomahawk.InfoSystem = Tomahawk.InfoSystem || {};
Tomahawk.InfoSystem.InfoType = Object.create(null);
Tomahawk.InfoSystem.InfoType.InfoNoInfo = 0; //WARNING: *ALWAYS* keep this first!
@@ -92,25 +92,6 @@ Tomahawk.InfoSystem.PushInfoFlags = Object.create(null);
Tomahawk.InfoSystem.PushInfoFlags.PushNoFlag = 1;
Tomahawk.InfoSystem.PushInfoFlags.PushShortUrlFlag = 2;
Tomahawk.InfoSystem._infoPluginIdCounter = 0;
Tomahawk.InfoSystem._infoPluginHash = Object.create(null);
Tomahawk.InfoSystem.addInfoPlugin = function (infoPlugin) {
var infoPluginId = Tomahawk.InfoSystem._infoPluginIdCounter++;
Tomahawk.InfoSystem._infoPluginHash[infoPluginId] = infoPlugin;
Tomahawk.InfoSystem.nativeAddInfoPlugin(infoPluginId);
};
Tomahawk.InfoSystem.getInfoPlugin = function (infoPluginId) {
return Tomahawk.InfoSystem._infoPluginHash[infoPluginId];
};
Tomahawk.InfoSystem.removeInfoPlugin = function (infoPluginId) {
Tomahawk.log('Removing info plugins from JS is not implemented yet');
Tomahawk.assert(false);
};
Tomahawk.InfoSystem.InfoPlugin = {
infoTypeString: function (infoType) {
for (var currentInfoTypeString in Tomahawk.InfoSystem.InfoType) {
@@ -119,13 +100,8 @@ Tomahawk.InfoSystem.InfoPlugin = {
}
}
},
// we can get around infoPluginId here probably ... but internal either way
_notInCache: function (infoPluginId, requestId, requestType, criteria) {
this.notInCache(requestType, criteria).then(function(result) {
Tomahawk.InfoSystem.nativeAddInfoRequestResult(infoPluginId, requestId, result.maxAge, result.data);
}).catch(function() {
// TODO: how to handle errors here?!
});
_notInCache: function (params) {
return this.notInCache(params.type, params.criteria);
},
notInCache: function (infoType, criteria) {
var requestMethod = 'request' + this.infoTypeString(infoType);
@@ -136,14 +112,8 @@ Tomahawk.InfoSystem.InfoPlugin = {
var pushMethod = 'push' + this.infoTypeString(pushData.type);
return this[pushMethod](pushData);
},
// we can get around infoPluginId here probably ... but internal either way
_getInfo: function (infoPluginId, requestId, type, infoHash) {
this.getInfo(type, infoHash).then(function(result) {
Tomahawk.InfoSystem.nativeGetCachedInfo(infoPluginId, requestId, result.newMaxAge, result.criteria)
}, function() {
Tomahawk.log("Call nativeDataError");
Tomahawk.InfoSystem.nativeDataError();
});
_getInfo: function (params) {
return this.getInfo(params.type, params.data);
},
getInfo: function (type, infoHash) {
var getInfoMethod = 'get' + this.infoTypeString(type);

View File

@@ -615,8 +615,8 @@ Tomahawk.PluginManager = {
Tomahawk.registerScriptPlugin(type, object.id);
},
invoke: function (requestId, objectId, methodName, params ) {
Tomahawk.log("requestId: " + requestId + " objectId: " + objectId + " methodName: " + methodName + " params: " + params);
invokeSync: function (objectId, methodName, params) {
if (!this.objects[objectId]) {
Tomahawk.log("Object not found!");
} else {
@@ -625,7 +625,15 @@ Tomahawk.PluginManager = {
}
}
Promise.resolve(this.objects[objectId][methodName](params)).then(function (result) {
if (typeof this.objects[objectId][methodName] === 'function') {
return this.objects[objectId][methodName](params);
}
return this.objects[objectId][methodName];
},
invoke: function (requestId, objectId, methodName, params ) {
Promise.resolve(this.invokeSync(objectId, methodName, params)).then(function (result) {
if (typeof result === 'object') {
Tomahawk.reportScriptJobResults({
requestId: requestId,
@@ -634,7 +642,7 @@ Tomahawk.PluginManager = {
} else {
Tomahawk.reportScriptJobResults({
requestId: requestId,
error: "Scripts need to return objects for requests"
error: "Scripts need to return objects for requests: methodName: " + methodName + " params: " + JSON.encode(params)
});
}
}, function (error) {