Added try repeater and opendir
This commit is contained in:
parent
62684b80e7
commit
b79775f82c
35
lib/Utils.js
35
lib/Utils.js
|
@ -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;
|
Loading…
Reference in New Issue