From 3524e6abac941835edfe71fd87287dfc00b6562c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 17 Aug 2010 12:03:20 +0200 Subject: [PATCH] ox.setInterval, move permission check into function --- OxFF/components/OxFF.js | 36 ++++++++++++++++++++++-------------- OxFF/modules/utils.jsm | 5 +++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/OxFF/components/OxFF.js b/OxFF/components/OxFF.js index 57f14e6..e4c0928 100644 --- a/OxFF/components/OxFF.js +++ b/OxFF/components/OxFF.js @@ -176,21 +176,15 @@ OxFF.prototype = { } return this._access; }, + api: function(action, data, callback) { var _this = this; if (typeof(data) == 'function') { callback = data; data = {}; } - - if(!this._access) { - this.debug('permission deinied', action, data); - return false; - } - if(!this._user) { - this.debug('login first', action, data); - return false; - } + if(!this.canAccess()) + return false; data["site"] = this._site; data["user"] = this._user; @@ -269,11 +263,15 @@ OxFF.prototype = { }, uploadVideo: function(oshash, url, profile, callback, progress) { var _this = this; + + if(!this.canAccess()) + return false; + if(progress) progress = progress.callback; - var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback(function() { - return _this.api('extract', {'oshash': oshash, 'media': profile}, function(result) { + + var timer = ox.setInterval(function() { + _this.api('extract', {'oshash': oshash, 'media': profile}, function(result) { var data = JSON.parse(result); if (data.status == 'extracting') { if(progress) { @@ -289,8 +287,7 @@ OxFF.prototype = { } } }); - } ,2000, Ci.nsITimer.TYPE_REPEATING_SLACK); - + }, 2000); return true; }, files: function(volume, callback) { @@ -356,6 +353,17 @@ OxFF.prototype = { this._access = false; oxff.access(this._site, this._access); }, + canAccess: function() { + if(!this._access) { + this.debug('permission deinied', action, data); + return false; + } + if(!this._user) { + this.debug('login first', action, data); + return false; + } + return true; + }, startDaemon: function() { var _this = this; //if daemon is already running to not start it again diff --git a/OxFF/modules/utils.jsm b/OxFF/modules/utils.jsm index a07e846..e6ccc00 100644 --- a/OxFF/modules/utils.jsm +++ b/OxFF/modules/utils.jsm @@ -11,6 +11,11 @@ let ox = { var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT); }, + setInterval: function(callback, timeout) { + var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); + timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_REPEATING_SLACK); + return timer; + }, glob: function (path) { /* return array of all files(in all subdirectories) for given directory