]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/bootstrap.js
Import 1.0b7.1 supporting Firefox up to 8.*
[dactyl.git] / common / bootstrap.js
index b17cba4c3be23af9c6d3e9a4a4d504dbeee81a78..ccf100761e2f56b331f9dfa664ec72b6098aa6ac 100755 (executable)
@@ -29,6 +29,8 @@ const resourceProto = Services.io.getProtocolHandler("resource")
 const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
 const manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 
+const BOOTSTRAP_JSM = "resource://dactyl/bootstrap.jsm";
+
 const BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap";
 JSMLoader = JSMLoader || BOOTSTRAP_CONTRACT in Cc && Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader;
 
@@ -41,7 +43,6 @@ if (!JSMLoader && "@mozilla.org/fuel/application;1" in Components.classes)
                           .getService(Components.interfaces.extIApplication)
                           .storage.get("dactyl.JSMLoader", null);
 
-
 function reportError(e) {
     dump("\ndactyl: bootstrap: " + e + "\n" + (e.stack || Error().stack) + "\n");
     Cu.reportError(e);
@@ -156,7 +157,6 @@ function init() {
     let chars = "0123456789abcdefghijklmnopqrstuv";
     for (let n = Date.now(); n; n = Math.round(n / chars.length))
         suffix += chars[n % chars.length];
-    suffix = "";
 
     for each (let line in manifest.split("\n")) {
         let fields = line.split(/\s+/);
@@ -173,12 +173,22 @@ function init() {
             break;
 
         case "resource":
+            var hardSuffix = /^[^\/]*/.exec(fields[2])[0];
+
             resources.push(fields[1], fields[1] + suffix);
             resourceProto.setSubstitution(fields[1], getURI(fields[2]));
             resourceProto.setSubstitution(fields[1] + suffix, getURI(fields[2]));
         }
     }
 
+    // Flush the cache if necessary, just to be paranoid
+    let pref = "extensions.dactyl.cacheFlushCheck";
+    let val  = addon.version + "-" + hardSuffix;
+    if (!Services.prefs.prefHasUserValue(pref) || Services.prefs.getCharPref(pref) != val) {
+        Services.obs.notifyObservers(null, "startupcache-invalidate", "");
+        Services.prefs.setCharPref(pref, val);
+    }
+
     try {
         module("resource://dactyl-content/disable-acr.jsm").init(addon.id);
     }
@@ -186,16 +196,23 @@ function init() {
         reportError(e);
     }
 
-    if (JSMLoader && JSMLoader.bump !== 4) // Temporary hack
-        Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm",
-            Cu.import("resource://dactyl/bootstrap.jsm", global));
+    if (JSMLoader) {
+        if (Cu.unload) {
+            Cu.unload(BOOTSTRAP_JSM);
+            for (let [name] in Iterator(JSMLoader.globals))
+                Cu.unload(~name.indexOf(":") ? name : "resource://dactyl" + JSMLoader.suffix + "/" + name);
+        }
+        else if (JSMLoader.bump != 5) // Temporary hack
+            Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm",
+                Cu.import(BOOTSTRAP_JSM, global));
+    }
 
-    if (!JSMLoader || JSMLoader.bump !== 4)
-        Cu.import("resource://dactyl/bootstrap.jsm", global);
+    if (!JSMLoader || JSMLoader.bump !== 5 || Cu.unload)
+        Cu.import(BOOTSTRAP_JSM, global);
 
     JSMLoader.bootstrap = this;
 
-    JSMLoader.load("resource://dactyl/bootstrap.jsm", global);
+    JSMLoader.load(BOOTSTRAP_JSM, global);
 
     JSMLoader.init(suffix);
     JSMLoader.load("base.jsm", global);
@@ -211,9 +228,9 @@ function init() {
                 wrappedJSObject: {}
             },
             createInstance: function () this.instance
-        })
+        });
 
-    Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = JSMLoader;
+    Cc[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader = !Cu.unload && JSMLoader;
 
     for each (let component in components)
         component.register();
@@ -233,11 +250,11 @@ function shutdown(data, reason) {
             reportError(e);
         }
 
-        if ([ADDON_UPGRADE, ADDON_DOWNGRADE, ADDON_UNINSTALL].indexOf(reason) >= 0)
+        if (~[ADDON_UPGRADE, ADDON_DOWNGRADE, ADDON_UNINSTALL].indexOf(reason))
             Services.obs.notifyObservers(null, "dactyl-purge", null);
 
-        Services.obs.notifyObservers(null, "dactyl-cleanup", null);
-        Services.obs.notifyObservers(null, "dactyl-cleanup-modules", null);
+        Services.obs.notifyObservers(null, "dactyl-cleanup", reasonToString(reason));
+        Services.obs.notifyObservers(null, "dactyl-cleanup-modules", reasonToString(reason));
 
         JSMLoader.purge();
         for each (let [category, entry] in categories)