Added try repeater and opendir

This commit is contained in:
Jiiks 2016-05-05 13:04:15 +03:00
parent 62684b80e7
commit b79775f82c
1 changed files with 34 additions and 1 deletions

View File

@ -2,7 +2,7 @@
* Version: 1.4
* Author: Jiiks | http://jiiks.net
* Date: 25/08/2015 - 09:19
* Last Updated: 01/05/2016
* Last Updated: 20/04/2016
* https://github.com/Jiiks/BetterDiscordApp
*/
@ -224,4 +224,37 @@ Utils.prototype.mkdirSync = function(path) {
}
};
Utils.prototype.try = function(func, attempts, attempt, message, success, err) {
var self = this;
attempt = attempt || 0;
attempt++;
if(attempt > attempts) {
err();
return;
}
setTimeout(function() {
self.warn(message + ", retrying #" + attempt);
if(!func()) {
self.try(func, attempts, attempt, message, success, err);
return;
}
success();
}, 1000);
};
Utils.prototype.openDir = function(path) {
switch(process.platform) {
case "win32":
require("child_process").exec('start "" "' + path + '"');
break;
case "darwin":
require("child_process").exec('open ' + path);
break;
}
};
exports.Utils = Utils;