diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2015-03-23 23:19:24 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2015-03-25 20:08:48 +0100 |
commit | 92ed83c72e2e1006bd2c94cbe02870f7d2404cae (patch) | |
tree | 4e3ec6ae0e28c0fa2c4767170d109cb8982cfab2 /xul-ext/chrome | |
parent | 07b84b96bee626471db5f5dc284f4cd00a0d56ff (diff) |
Use about:config to determine the socket path and perms.
Diffstat (limited to 'xul-ext/chrome')
-rw-r--r-- | xul-ext/chrome/content/icevault.js | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/xul-ext/chrome/content/icevault.js b/xul-ext/chrome/content/icevault.js index fe2cb50..f2c4c79 100644 --- a/xul-ext/chrome/content/icevault.js +++ b/xul-ext/chrome/content/icevault.js @@ -21,7 +21,8 @@ var icevault = (function() { const Cc = Components.classes, CC = Components.Constructor, - Ci = Components.interfaces; + Ci = Components.interfaces, + Cu = Components.utils; const UnixServerSocket = CC( "@mozilla.org/network/server-socket;1" , "nsIServerSocket" @@ -36,17 +37,24 @@ var icevault = (function() { , "nsIConverterOutputStream" , "init" ); - // XXX should be changeable from the preferences - let sockName = Cc["@mozilla.org/file/directory_service;1"] - .getService(Ci.nsIProperties) - .get("ProfD", Ci.nsIFile); - sockName.append("S.IceVault"); - const sockPerms = parseInt("0770", 8); - const convertStringToUTF8 = Cc["@mozilla.org/intl/utf8converterservice;1"] .getService(Ci.nsIUTF8ConverterService) .convertStringToUTF8; + + let prefs = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefService) + .getBranch("extensions.icevault."); + var sockPath = prefs.getCharPref("socketPath", Ci.nsIRelativeFilePref); + const sockPerms = parseInt(prefs.getCharPref("socketPerms"), 8); + + Cu.import("resource://gre/modules/FileUtils.jsm"); + if (sockPath.charAt(0) == '/') + sockPath = new FileUtils.File(sockPath); + else // take relative files in the profile directory + sockPath = FileUtils.getFile("ProfD", [sockPath]); + + // Write the given UTF8 string to the ConverterOutputStream, then flush var send = function(stream, msg) { //console.log("Sending: " + msg) @@ -199,11 +207,11 @@ var icevault = (function() { if (Application.storage.has("IceVault.serverSocket")) server = Application.storage.get("IceVault.serverSocket", null); else { - console.log("Initializing IceVault"); + console.log("Initializing IceVault (listening on " + sockPath.path + ")"); try { - if (sockName.exists()) - sockName.remove(false); // remove stalled socket - server = new UnixServerSocket(sockName, sockPerms, -1); + if (sockPath.exists()) + sockPath.remove(false); // remove stalled socket + server = new UnixServerSocket(sockPath, sockPerms, -1); } finally { Application.storage.set("IceVault.serverSocket", server); @@ -213,10 +221,10 @@ var icevault = (function() { }, clean: function() { - if (!Application.windows.length && sockName.exists()) { + if (!Application.windows.length && sockPath.exists()) { // remove the socket if the last window was just closed - console.log("Removing " + sockName.path); - sockName.remove(false); + console.log("Removing " + sockPath.path); + sockPath.remove(false); } } } |