diff --git a/OxFF/bin/oxd.py b/OxFF/bin/oxd.py index b0d2909..8919492 100755 --- a/OxFF/bin/oxd.py +++ b/OxFF/bin/oxd.py @@ -718,6 +718,7 @@ class OxControl(Resource): if __name__ == '__main__': db = 'dev.sqlite' + db = sys.argv[1] port = 2620 username = 'fix' password = 'me' diff --git a/OxFF/components/OxFF.js b/OxFF/components/OxFF.js index e0a9581..3efee9f 100644 --- a/OxFF/components/OxFF.js +++ b/OxFF/components/OxFF.js @@ -9,7 +9,9 @@ const Cc = Components.classes; const Ci = Components.interfaces; +Components.utils.import("resource://gre/modules/AddonManager.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + Components.utils.import("resource://ox/utils.jsm"); var OxFFFactory = @@ -35,6 +37,8 @@ function OxFF() { this._site = 'localhost'; } this.access(); + + this._window.addEventListener("unload", function() { _this.logout() }, false); } OxFF.prototype = { @@ -148,6 +152,7 @@ OxFF.prototype = { return this._access; }, api: function(action, data, callback) { + var _this = this; if (typeof(data) == 'function') { callback = data; data = {}; @@ -169,9 +174,7 @@ OxFF.prototype = { .createInstance(Ci.nsIXMLHttpRequest); req.addEventListener("error", function(e) { - //should check that it was infact not able to connect to server _this.startDaemon(); - //does this need a timeout? ox.setTimeout(function() { _this.api(action, data, callback); }, 500); }, false); req.addEventListener("load", function(e) { @@ -213,7 +216,7 @@ OxFF.prototype = { }, logout: function(user) { var _this = this; - this.api('shutdown', function() { + this.api('stop', function() { _this._user = null; }); return true; @@ -223,14 +226,13 @@ OxFF.prototype = { return true; }, - addVolume: function(archive) { + addVolume: function() { if(!this._access) { return false; } - //var volumes = this.getVolumes(domain); const nsIFilePicker = Ci.nsIFilePicker; var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); - fp.init(this._window, "Choose location of " + archive, nsIFilePicker.modeGetFolder); + fp.init(this._window, "Add Volume to " + this._site, nsIFilePicker.modeGetFolder); fp.appendFilters(nsIFilePicker.filterAll); var rv = fp.show(); if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { @@ -284,6 +286,12 @@ OxFF.prototype = { q.executeStep(); }, startDaemon: function() { + var _this = this; + //if daemon is already running to not start it again + if(this._daemon && this._daemon.isRunning) { + this.debug('daemon is still starting up, not starting again'); + return false; + } var osString = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS; var daemon = ""; if (osString == "WINNT") @@ -295,16 +303,16 @@ OxFF.prototype = { try { file.permissions = 0755; } catch (e) {} - var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess); - process.init(file); - var args = []; - process.run(false, args, args.length); + _this._daemon = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess); + _this._daemon.init(file); + var args = [ox.getDBFile().path]; + _this._daemon.runw(false, args, args.length); } - Components.utils.import("resource://gre/modules/AddonManager.jsm"); AddonManager.getAddonByID(this.extensionID, function(addon) { - if (addon.hasResource(daemon)) { - var resource = addon.getResourceURI(daemon); + if (addon.hasResource('bin')) { + var resource = addon.getResourceURI('bin'); var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile); + file.append(daemon); runDaemon(file); } }); diff --git a/OxFF/modules/utils.jsm b/OxFF/modules/utils.jsm index 6565ea6..1a4b93e 100644 --- a/OxFF/modules/utils.jsm +++ b/OxFF/modules/utils.jsm @@ -7,10 +7,14 @@ const Cc = Components.classes; const Ci = Components.interfaces; let ox = { - getDB: function() { + getDBFile: function() { var file = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties) .get("ProfD", Ci.nsIFile); file.append("OxFF.sqlite"); + return file; + }, + getDB: function() { + var file = this.getDBFile(); var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService); var conn = storageService.openDatabase(file); conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS site (site varchar(1024) unique, access INT)");