diff --git a/content/treestyletab/treestyletab.xul b/content/treestyletab/treestyletab.xul
index e0bee6ce..4dafd284 100644
--- a/content/treestyletab/treestyletab.xul
+++ b/content/treestyletab/treestyletab.xul
@@ -16,7 +16,6 @@
-
diff --git a/modules/base.js b/modules/base.js
index a922479c..5186abb2 100644
--- a/modules/base.js
+++ b/modules/base.js
@@ -71,6 +71,8 @@ XPCOMUtils.defineLazyGetter(this, 'autoScroll', function() {
Components.utils.import('resource://treestyletab-modules/lib/autoScroll.js', {});
return window['piro.sakura.ne.jp'].autoScroll;
});
+XPCOMUtils.defineLazyModuleGetter(this, 'UninstallationListener',
+ 'resource://treestyletab-modules/lib/UninstallationListener.js');
XPCOMUtils.defineLazyModuleGetter(this, 'confirmWithPopup', 'resource://treestyletab-modules/lib/confirmWithPopup.js');
XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils');
@@ -311,6 +313,8 @@ var TreeStyleTabBase = {
this.addPrefListener(this);
+ this.initUninstallationListener();
+
this.onPrefChange('extensions.treestyletab.indent.vertical');
this.onPrefChange('extensions.treestyletab.indent.horizontal');
this.onPrefChange('extensions.treestyletab.clickOnIndentSpaces.enabled');
@@ -488,7 +492,38 @@ var TreeStyleTabBase = {
}
utils.setTreePref('prefsVersion', this.kPREF_VERSION);
},
-
+
+ initUninstallationListener : function TSTWindow_initUninstallationListener()
+ {
+ var restorePrefs = function() {
+ // Remove pref listener before restore backuped prefs.
+ prefs.removePrefListener(this);
+
+ let restorePrefs = [
+ 'browser.tabs.loadFolderAndReplace',
+ 'browser.tabs.insertRelatedAfterCurrent',
+ 'extensions.stm.tabBarMultiRows' // Super Tab Mode
+ ];
+ for (let i = 0, maxi = restorePrefs.length; i < maxi; i++)
+ {
+ let pref = restorePrefs[i];
+ let backup = prefs.getPref(pref+'.backup');
+ if (backup === null) continue;
+ // we have to set to ".override" pref, to avoid unexpectedly reset by the preference listener.
+ prefs.setPref(pref+'.override', backup);
+ // restore user preference.
+ prefs.setPref(pref, backup);
+ // clear backup pref.
+ prefs.clearPref(pref+'.backup');
+ }
+ }.bind(this);
+ new UninstallationListener({
+ id : 'treestyletab@piro.sakura.ne.jp',
+ onuninstalled : restorePrefs,
+ ondisabled : restorePrefs
+ });
+ },
+
updateAeroPeek : function utils_updateAeroPeek()
{
var ns = {};
diff --git a/content/treestyletab/res/UninstallationListener.js b/modules/lib/UninstallationListener.js
similarity index 83%
rename from content/treestyletab/res/UninstallationListener.js
rename to modules/lib/UninstallationListener.js
index 92fceafa..c8fb7959 100644
--- a/content/treestyletab/res/UninstallationListener.js
+++ b/modules/lib/UninstallationListener.js
@@ -13,6 +13,24 @@
original:
http://github.com/piroor/fxaddonlibs/blob/master/UninstallationListener.js
*/
+
+/* To work as a JS Code Module */
+if (typeof window == 'undefined' ||
+ (window && typeof window.constructor == 'function')) {
+ this.EXPORTED_SYMBOLS = ['UninstallationListener'];
+
+ // If namespace.jsm is available, export symbols to the shared namespace.
+ // See: http://github.com/piroor/fxaddonlibs/blob/master/namespace.jsm
+ try {
+ let ns = {};
+ Components.utils.import('resource://my-modules/namespace.jsm', ns);
+ /* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
+ }
+ catch(e) {
+ window = {};
+ }
+}
+
(function() {
const currentRevision = 2;
@@ -165,3 +183,7 @@
}
};
})();
+
+if (window != this) { // work as a JS Code Module
+ this.UninstallationListener = window['piro.sakura.ne.jp'].UninstallationListener;
+}
diff --git a/modules/window.js b/modules/window.js
index 44aa96e7..1a8bc6aa 100644
--- a/modules/window.js
+++ b/modules/window.js
@@ -40,6 +40,11 @@ const Ci = Components.interfaces;
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
+XPCOMUtils.defineLazyModuleGetter(this, "prefs",
+ 'resource://treestyletab-modules/lib/prefs.js');
+XPCOMUtils.defineLazyModuleGetter(this, 'UninstallationListener',
+ 'resource://treestyletab-modules/lib/UninstallationListener.js');
+
XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
Components.utils.import('resource://treestyletab-modules/base.js');
@@ -379,46 +384,18 @@ TreeStyleTabWindow.prototype = {
initUninstallationListener : function TSTWindow_initUninstallationListener()
{
- var namespace = {};
- Components.utils.import(
- 'resource://treestyletab-modules/lib/prefs.js',
- namespace
- );
- var prefs = namespace.prefs;
- namespace = void(0);
- var self = this;
var restorePrefs = function() {
if (prefs.getPref('extensions.treestyletab.tabsOnTop.originalState')) {
prefs.clearPref('extensions.treestyletab.tabsOnTop.originalState');
try {
- self.browser.treeStyleTab.position = 'top';
+ this.browser.treeStyleTab.position = 'top';
}
catch(e) {
}
- self.window.TabsOnTop.enabled = true;
+ this.window.TabsOnTop.enabled = true;
}
-
- if (!prefs) return;
-
- let restorePrefs = [
- 'browser.tabs.loadFolderAndReplace',
- 'browser.tabs.insertRelatedAfterCurrent',
- 'extensions.stm.tabBarMultiRows' // Super Tab Mode
- ];
- for (let i = 0, maxi = restorePrefs.length; i < maxi; i++)
- {
- let pref = restorePrefs[i];
- let backup = prefs.getPref(pref+'.backup');
- if (backup === null) continue;
- // we have to set to ".override" pref, to avoid unexpectedly reset by the preference listener.
- prefs.setPref(pref+'.override', backup);
- // restore user preference.
- prefs.setPref(pref, backup);
- // clear backup pref.
- prefs.clearPref(pref+'.backup');
- }
- };
- new this.window['piro.sakura.ne.jp'].UninstallationListener({
+ }.bind(this);
+ new UninstallationListener({
id : 'treestyletab@piro.sakura.ne.jp',
onuninstalled : restorePrefs,
ondisabled : restorePrefs