Update library

This commit is contained in:
YUKI Hiroshi 2016-09-07 15:57:00 +09:00
parent 92dd8adf82
commit 88cf5df47f

View File

@ -1,189 +1,112 @@
/* /**
Uninstallation Listener Library * @fileOverview Uninstallation Listener Library
* @author YUKI "Piro" Hiroshi
Usage: * @version 3
new window['piro.sakura.ne.jp'].UninstallationListener({ *
id : 'test@exmaple.com', * @license
onuninstalled : function() { ... }, * The MIT License, Copyright (c) 2009-2016 YUKI "Piro" Hiroshi.
ondisabled : function() { ... } * https://github.com/piroor/fxaddonlib-uninstallation-listener/blob/master/license.txt
}); * @url https://github.com/piroor/fxaddonlib-uninstallation-listener
*
license: The MIT License, Copyright (c) 2009-2011 YUKI "Piro" Hiroshi * Usage:
http://github.com/piroor/fxaddonlibs/blob/master/license.txt * new UninstallationListener({
original: * id : 'test@exmaple.com',
http://github.com/piroor/fxaddonlibs/blob/master/UninstallationListener.js * onuninstalled : function() { ... },
*/ * ondisabled : function() { ... }
* });
/* To work as a JS Code Module */ */
if (typeof window == 'undefined' ||
(window && typeof window.constructor == 'function')) { var EXPORTED_SYMBOLS = ['UninstallationListener'];
this.EXPORTED_SYMBOLS = ['UninstallationListener'];
// If namespace.jsm is available, export symbols to the shared namespace. const Cc = Components.classes;
// See: http://github.com/piroor/fxaddonlibs/blob/master/namespace.jsm const Ci = Components.interfaces;
try {
let ns = {}; const ObserverService = Cc['@mozilla.org/observer-service;1']
Components.utils.import('resource://my-modules/namespace.jsm', ns); .getService(Ci.nsIObserverService);
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
} var { AddonManager } = Components.utils.import('resource://gre/modules/AddonManager.jsm', {});
catch(e) {
window = {}; var UninstallationListener = function(aArguments) {
} this.init(aArguments);
} };
UninstallationListener.prototype = {
(function() { onEnabling : function(aAddon, aRestartRequired) {},
const currentRevision = 2; onEnabled : function(aAddon) {},
onDisabling : function(aAddon, aRestartRequired) {
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; if (aAddon.id == this.id) {
this.toBeDisabled = true;
var loadedRevision = 'UninstallationListener' in window['piro.sakura.ne.jp'] ? }
window['piro.sakura.ne.jp'].UninstallationListener.prototype.revision : },
0 ; onDisabled : function(aAddon)
if (loadedRevision && loadedRevision > currentRevision) { {
return; if (aAddon.id == this.id) {
} if (this.ondisabled) this.ondisabled();
delete this.ondisabled;
const Cc = Components.classes; }
const Ci = Components.interfaces; },
onInstalling : function(aAddon, aRestartRequired) {},
const ObserverService = Cc['@mozilla.org/observer-service;1'] onInstalled : function(aAddon) {},
.getService(Ci.nsIObserverService); onUninstalling : function(aAddon, aRestartRequired) {
if (aAddon.id == this.id) {
var AddonManager; this.toBeUninstalled = true;
try { }
let ns = {}; },
Components.utils.import('resource://gre/modules/AddonManager.jsm', ns); onUninstalled : function(aAddon)
AddonManager = ns.AddonManager; {
} if (aAddon.id == this.id) {
catch(e) { if (this.onuninstalled) this.onuninstalled();
} delete this.onuninstalled;
}
window['piro.sakura.ne.jp'].UninstallationListener = function(aArguments) { },
this.init(aArguments); onOperationCancelled : function(aAddon)
}; {
window['piro.sakura.ne.jp'].UninstallationListener.prototype = { if (aAddon.id == this.id) {
revision : currentRevision, this.toBeDisabled = false;
this.toBeUninstalled = false;
// for Firefox 3.6 or older }
observe : function(aSubject, aTopic, aData) },
{ onPropertyChanged : function(aAddon, aProperties) {},
switch (aTopic)
{ init : function(aArguments)
case 'em-action-requested': {
switch (aData) if (!aArguments) return;
{
case 'item-uninstalled': this.id = (typeof aArguments == 'string') ? aArguments : aArguments.id ;
if (this.isTargetExtension(aSubject))
this.toBeUninstalled = true; this.toBeUninstalled = false;
break; this.toBeDisabled = false;
case 'item-cancel-action': if (typeof aArguments == 'object') {
if (this.isTargetExtension(aSubject)) { this.onuninstalled = aArguments.onuninstalled;
this.toBeUninstalled = false; this.ondisabled = aArguments.ondisabled;
this.toBeDisabled = false; }
}
break; AddonManager.addAddonListener(this);
case 'item-disabled': ObserverService.addObserver(this, 'quit-application-granted', false);
if (this.isTargetExtension(aSubject)) },
this.toBeDisabled = true;
break; destroy : function()
case 'item-enabled': {
if (this.isTargetExtension(aSubject)) if (this.toBeUninstalled && this.onuninstalled)
this.toBeDisabled = false; this.onuninstalled();
break; delete this.onuninstalled;
}
return; if (this.toBeDisabled && this.ondisabled)
this.ondisabled();
case 'quit-application-granted': delete this.ondisabled;
this.destroy();
return; AddonManager.removeAddonListener(this);
} ObserverService.removeObserver(this, 'quit-application-granted');
}, },
isTargetExtension : function(aSubject)
{ observe : function(aSubject, aTopic, aData)
return (aSubject instanceof Ci.nsIUpdateItem) && (aSubject.id == this.id); {
}, switch (aTopic)
{
// for Firefox 4 or later case 'quit-application-granted':
onEnabling : function(aAddon, aRestartRequired) {}, this.destroy();
onEnabled : function(aAddon) {}, return;
onDisabling : function(aAddon, aRestartRequired) { }
if (aAddon.id == this.id) { }
this.toBeDisabled = true; };
}
},
onDisabled : function(aAddon)
{
if (aAddon.id == this.id) {
if (this.ondisabled) this.ondisabled();
delete this.ondisabled;
}
},
onInstalling : function(aAddon, aRestartRequired) {},
onInstalled : function(aAddon) {},
onUninstalling : function(aAddon, aRestartRequired) {
if (aAddon.id == this.id) {
this.toBeUninstalled = true;
}
},
onUninstalled : function(aAddon)
{
if (aAddon.id == this.id) {
if (this.onuninstalled) this.onuninstalled();
delete this.onuninstalled;
}
},
onOperationCancelled : function(aAddon)
{
if (aAddon.id == this.id) {
this.toBeDisabled = false;
this.toBeUninstalled = false;
}
},
onPropertyChanged : function(aAddon, aProperties) {},
init : function(aArguments)
{
if (!aArguments) return;
this.id = (typeof aArguments == 'string') ? aArguments : aArguments.id ;
this.toBeUninstalled = false;
this.toBeDisabled = false;
if (typeof aArguments == 'object') {
this.onuninstalled = aArguments.onuninstalled;
this.ondisabled = aArguments.ondisabled;
}
if (AddonManager) { // Firefox 4 or later
AddonManager.addAddonListener(this);
}
else {
ObserverService.addObserver(this, 'em-action-requested', false);
}
ObserverService.addObserver(this, 'quit-application-granted', false);
},
destroy : function()
{
if (this.toBeUninstalled && this.onuninstalled)
this.onuninstalled();
delete this.onuninstalled;
if (this.toBeDisabled && this.ondisabled)
this.ondisabled();
delete this.ondisabled;
if (AddonManager) { // Firefox 4 or later
AddonManager.removeAddonListener(this);
}
else {
ObserverService.removeObserver(this, 'em-action-requested');
}
ObserverService.removeObserver(this, 'quit-application-granted');
}
};
})();
if (window != this) { // work as a JS Code Module
this.UninstallationListener = window['piro.sakura.ne.jp'].UninstallationListener;
}