From b79775f82ca06c5686aaa9942d4da36c8846acb8 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 5 May 2016 13:04:15 +0300 Subject: [PATCH] Added try repeater and opendir --- lib/Utils.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/Utils.js b/lib/Utils.js index 0d7441d..8d2950c 100644 --- a/lib/Utils.js +++ b/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; \ No newline at end of file