Skip to content

Commit

Permalink
Configurable notification method, as suggested on #5
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocr committed Feb 16, 2014
1 parent 38865b5 commit 7afce70
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
35 changes: 32 additions & 3 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Cu.import("resource://gre/modules/AddonManager.jsm");
function LOG(m) (m = addon.name + ' Message @ '
+ (new Date()).toISOString() + "\n> " + m,
dump(m + "\n"), Services.console.logStringMessage(m));
function rsc(n) 'resource://' + addon.tag + '/' + n;

let i$ = {
onOpenWindow: function(aWindow) {
Expand All @@ -36,6 +37,22 @@ let i$ = {
onWindowTitleChange: function() {}
};

let showAlertNotification = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
showAlertNotification = showAlertNotification.showAlertNotification.bind(showAlertNotification);

function iNotify(aMsg, callback) {
let nme = addon.branch.getIntPref('nme');

if(nme == 2) {
showAlertNotification(rsc("icon.png"),addon.name,aMsg,!1,"",
(s,t) => t == "alertshow" || callback(t));
} else {
if(nme) Services.prompt.alert(null,addon.name,aMsg);

callback();
}
}

function onClickHanlder(ev) {
ev.preventDefault();

Expand All @@ -50,7 +67,7 @@ function onClickHanlder(ev) {
let d = this.ownerDocument,
l = this.lastChild,
f = this.firstChild;
l.textContent = 'Installing...';
l.textContent = ' Installing...';
f.className = f.className.replace('plus','hourglass');
d.body.appendChild(d.createElement('style')).textContent = '@keyframes '
+addon.tag+'{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}';
Expand Down Expand Up @@ -118,8 +135,7 @@ function onClickHanlder(ev) {
}
f.style.animation = null;
f.className = f.className.replace('hourglass',c);
Services.prompt.alert(null,addon.name,aMsg);
oFile.remove(!1);
iNotify(aMsg, () => oFile.remove(!1));
};

aInstall.addListener({
Expand Down Expand Up @@ -315,9 +331,18 @@ function startup(data) {
};
addon.branch = Services.prefs.getBranch('extensions.'+addon.tag+'.');

let io = Services.io;
io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler)
.setSubstitution(addon.tag,
io.newURI(__SCRIPT_URI_SPEC__+'/../',null,null));

i$.wmf(loadIntoWindowStub);
Services.wm.addListener(i$);

if(!addon.branch.getPrefType('nme')) {
addon.branch.setIntPref('nme',2);
}
addon.branch.setCharPref('version', addon.version);
});
}
Expand All @@ -328,6 +353,10 @@ function shutdown(data, reason) {

Services.wm.removeListener(i$);
i$.wmf(unloadFromWindow);

Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler)
.setSubstitution(addon.tag,null);
}

function install(data, reason) {}
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<em:id>{86054B0A-BD85-42F9-8E58-8794EC6F6EA1}</em:id>
<em:type>2</em:type>
<em:name>GitHub Extension Installer</em:name>
<em:version>1.4a3</em:version>
<em:version>1.4a4</em:version>
<em:creator>Diego Casorran &lt;[email protected]&gt;</em:creator>
<em:description>Install Browser Extensions straight from GitHub Repositories</em:description>
<em:contributor>Zulkarnain K.</em:contributor>
Expand Down
11 changes: 10 additions & 1 deletion options.xul
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version="1.0"?>
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<setting pref="extensions.githubextensioninstaller.nme" type="menulist" title="Notification Method">
<menulist>
<menupopup>
<menuitem value="0" label="None"/>
<menuitem value="1" label="Modal Dialog"/>
<menuitem value="2" label="Alerts Service"/>
</menupopup>
</menulist>
</setting>
<setting pref="extensions.githubextensioninstaller.prs" type="string" title="PR Repos:">
Comma-separated list of repositories where the button will be added on PRs.
Comma-separated list of repositories where the button will be added on its PRs.
</setting>
</vbox>

0 comments on commit 7afce70

Please sign in to comment.