mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-30 14:34:09 +02:00
Rewrite loadConfigurationFile in plugins.js to accept default config file
This commit is contained in:
parent
da71f2de2b
commit
520db2c32e
@ -2,25 +2,52 @@
|
|||||||
//
|
//
|
||||||
// Block: Setup a simple JavaScript object configuration loader.
|
// Block: Setup a simple JavaScript object configuration loader.
|
||||||
//
|
//
|
||||||
window.TDPF_loadConfigurationFile = function(pluginObject, fileName, onSuccess, onFailure){
|
(function(){
|
||||||
$TDP.readFile(pluginObject.$token, fileName, true).then(contents => {
|
var continueLoading = function(token, identifier, fileName, onSuccess, onFailure){
|
||||||
var obj;
|
$TDP.readFile(token, fileName, true).then(contents => {
|
||||||
|
var obj;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
obj = eval("("+contents+")");
|
obj = eval("("+contents+")");
|
||||||
}catch(err){
|
}catch(err){
|
||||||
if (!(onFailure && onFailure(err.message))){
|
if (!(onFailure && onFailure(err.message))){
|
||||||
alert("Problem loading '"+fileName+"' file for '"+pluginObject.$id+"' plugin, the JavaScript syntax is invalid: "+err.message);
|
alert("Problem loading '"+fileName+"' file for '"+identifier+"' plugin, the JavaScript syntax is invalid: "+err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
onSuccess && onSuccess(obj);
|
||||||
}
|
}).catch(err => {
|
||||||
|
if (!(onFailure && onFailure(err))){
|
||||||
|
alert("Problem loading '"+fileName+"' file for '"+identifier+"' plugin: "+err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
window.TDPF_loadConfigurationFile = function(pluginObject, fileNameUser, fileNameDefault, onSuccess, onFailure){
|
||||||
|
var identifier = pluginObject.$id;
|
||||||
|
var token = pluginObject.$token;
|
||||||
|
|
||||||
onSuccess && onSuccess(obj);
|
$TDP.checkFileExists(token, fileNameUser).then(exists => {
|
||||||
}).catch(err => {
|
if (!exists){
|
||||||
if (!(onFailure && onFailure(err))){
|
$TDP.readFile(token, fileNameDefault, true).then(contents => {
|
||||||
alert("Problem loading '"+fileName+"' file for '"+pluginObject.$id+"' plugin: "+err);
|
$TDP.writeFile(token, fileNameUser, contents);
|
||||||
}
|
continueLoading(token, identifier, fileNameUser, onSuccess, onFailure);
|
||||||
});
|
}).catch(err => {
|
||||||
};
|
if (!(onFailure && onFailure(err))){
|
||||||
|
alert("Problem generating '"+fileNameUser+"' file for '"+identifier+"' plugin: "+err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
continueLoading(token, identifier, fileNameUser, onSuccess, onFailure);
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
if (!(onFailure && onFailure(err))){
|
||||||
|
alert("Problem checking '"+fileNameUser+"' file for '"+identifier+"' plugin: "+err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
})();
|
||||||
})($TDP);
|
})($TDP);
|
Loading…
Reference in New Issue
Block a user