Skip to content

Commit 7afce70

Browse files
committed
Configurable notification method, as suggested on #5
1 parent 38865b5 commit 7afce70

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

bootstrap.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Cu.import("resource://gre/modules/AddonManager.jsm");
1919
function LOG(m) (m = addon.name + ' Message @ '
2020
+ (new Date()).toISOString() + "\n> " + m,
2121
dump(m + "\n"), Services.console.logStringMessage(m));
22+
function rsc(n) 'resource://' + addon.tag + '/' + n;
2223

2324
let i$ = {
2425
onOpenWindow: function(aWindow) {
@@ -36,6 +37,22 @@ let i$ = {
3637
onWindowTitleChange: function() {}
3738
};
3839

40+
let showAlertNotification = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
41+
showAlertNotification = showAlertNotification.showAlertNotification.bind(showAlertNotification);
42+
43+
function iNotify(aMsg, callback) {
44+
let nme = addon.branch.getIntPref('nme');
45+
46+
if(nme == 2) {
47+
showAlertNotification(rsc("icon.png"),addon.name,aMsg,!1,"",
48+
(s,t) => t == "alertshow" || callback(t));
49+
} else {
50+
if(nme) Services.prompt.alert(null,addon.name,aMsg);
51+
52+
callback();
53+
}
54+
}
55+
3956
function onClickHanlder(ev) {
4057
ev.preventDefault();
4158

@@ -50,7 +67,7 @@ function onClickHanlder(ev) {
5067
let d = this.ownerDocument,
5168
l = this.lastChild,
5269
f = this.firstChild;
53-
l.textContent = 'Installing...';
70+
l.textContent = ' Installing...';
5471
f.className = f.className.replace('plus','hourglass');
5572
d.body.appendChild(d.createElement('style')).textContent = '@keyframes '
5673
+addon.tag+'{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}';
@@ -118,8 +135,7 @@ function onClickHanlder(ev) {
118135
}
119136
f.style.animation = null;
120137
f.className = f.className.replace('hourglass',c);
121-
Services.prompt.alert(null,addon.name,aMsg);
122-
oFile.remove(!1);
138+
iNotify(aMsg, () => oFile.remove(!1));
123139
};
124140

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

334+
let io = Services.io;
335+
io.getProtocolHandler("resource")
336+
.QueryInterface(Ci.nsIResProtocolHandler)
337+
.setSubstitution(addon.tag,
338+
io.newURI(__SCRIPT_URI_SPEC__+'/../',null,null));
339+
318340
i$.wmf(loadIntoWindowStub);
319341
Services.wm.addListener(i$);
320342

343+
if(!addon.branch.getPrefType('nme')) {
344+
addon.branch.setIntPref('nme',2);
345+
}
321346
addon.branch.setCharPref('version', addon.version);
322347
});
323348
}
@@ -328,6 +353,10 @@ function shutdown(data, reason) {
328353

329354
Services.wm.removeListener(i$);
330355
i$.wmf(unloadFromWindow);
356+
357+
Services.io.getProtocolHandler("resource")
358+
.QueryInterface(Ci.nsIResProtocolHandler)
359+
.setSubstitution(addon.tag,null);
331360
}
332361

333362
function install(data, reason) {}

install.rdf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<em:id>{86054B0A-BD85-42F9-8E58-8794EC6F6EA1}</em:id>
55
<em:type>2</em:type>
66
<em:name>GitHub Extension Installer</em:name>
7-
<em:version>1.4a3</em:version>
7+
<em:version>1.4a4</em:version>
88
<em:creator>Diego Casorran &lt;[email protected]&gt;</em:creator>
99
<em:description>Install Browser Extensions straight from GitHub Repositories</em:description>
1010
<em:contributor>Zulkarnain K.</em:contributor>

options.xul

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?xml version="1.0"?>
22
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
3+
<setting pref="extensions.githubextensioninstaller.nme" type="menulist" title="Notification Method">
4+
<menulist>
5+
<menupopup>
6+
<menuitem value="0" label="None"/>
7+
<menuitem value="1" label="Modal Dialog"/>
8+
<menuitem value="2" label="Alerts Service"/>
9+
</menupopup>
10+
</menulist>
11+
</setting>
312
<setting pref="extensions.githubextensioninstaller.prs" type="string" title="PR Repos:">
4-
Comma-separated list of repositories where the button will be added on PRs.
13+
Comma-separated list of repositories where the button will be added on its PRs.
514
</setting>
615
</vbox>

0 commit comments

Comments
 (0)