aboutsummaryrefslogtreecommitdiffstats
path: root/xul-ext/chrome/content/icevault.js
diff options
context:
space:
mode:
Diffstat (limited to 'xul-ext/chrome/content/icevault.js')
-rw-r--r--xul-ext/chrome/content/icevault.js38
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);
}
}
}