Skip to content

Commit

Permalink
Made Copy ShortURL compatible with Firefox 4b11 and the latest addon-…
Browse files Browse the repository at this point in the history
…sdk.
  • Loading branch information
Fred Wenzel committed Feb 9, 2011
1 parent c9c43fe commit a6ed22d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const clipboard = require("clipboard"),
contextMenu = require("context-menu"),
data = require("self").data,
notify = require("simple-notify").notify,
prefs = require("preferences-service"),
self = require("self"),
xhr = require("xhr");

/* String constants */
Expand Down Expand Up @@ -37,7 +37,7 @@ exports.main = function(options, callbacks) {
/* Add and hook up context menu */
var item = contextMenu.Item({
label: 'Copy ShortURL',
contentScriptURL: self.data.url('js/find-short-url.js'),
contentScriptFile: data.url('js/find-short-url.js'),
onMessage: function(found_url) {
let url = found_url['url'];

Expand Down
41 changes: 22 additions & 19 deletions lib/simple-notify.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const {Cc,Ci} = require("chrome"),
notifications = require("notifications"),
const { Cc, Ci } = require("chrome"),
data = require("self").data,
prefs = require("preferences-service"),
self = require("self"),
tabs = require("tabs"),
timer = require("timer");
tabbrowser = require("tab-browser"),
timer = require("timer"),
windowutils = require("window-utils");

const addon_name = 'Copy ShortURL',
addon_icon = self.data.url('img/ruler.png'),
addon_icon32 = self.data.url('img/ruler32.png'),
addon_icon = data.url('img/ruler.png'),
addon_icon32 = data.url('img/ruler32.png'),

// Preferences
notification_pref = 'extensions.copyshorturl.notifications',
Expand All @@ -26,7 +26,7 @@ function notify(txt) {

// Box only
case 1:
boxNotify(txt, win);
boxNotify(txt);
break;

// Growl with box fallback
Expand All @@ -35,19 +35,24 @@ function notify(txt) {
try {
growlNotify(txt);
} catch (e) {
boxNotify(txt, win);
boxNotify(txt);
}
break;
}
}

/** Notify via Growl */
/** Notify via Growl. Throws exception if unavailable. */
function growlNotify(txt) {
notifications.notify({
title: addon_name,
iconURL: addon_icon32,
text: txt
});
// Ugly: Import alert service. If unavailable, throws exception.
// Would use notifications.notify if that let me know when Growl is
// unavailable.
let alertServ = Cc["@mozilla.org/alerts-service;1"].
getService(Ci.nsIAlertsService);
alertServ.showAlertNotification(
addon_icon32, // icon
addon_name, // title
txt // text
);
}

/** Notify via notification box. */
Expand All @@ -71,10 +76,8 @@ function boxNotify(txt) {
* Courtesy of bug 533649.
*/
function getNotificationBox() {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator),
chromeWindow = wm.getMostRecentWindow("navigator:browser"),
notificationBox = chromeWindow.getNotificationBox(tabs.activeTab.contentWindow);
let browser = windowutils.activeBrowserWindow.gBrowser,
notificationBox = browser.getNotificationBox();
return notificationBox;
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"description": "If a page exposes a short URL via a 'link rev=canonical' header, fetch it and copy it to the clipboard. If not, create a shorturl at tinyurl and copy it to the clipboard as well.",
"author": "Fred Wenzel <[email protected]>",
"dependencies": [
"jetpack-core"
"addon-kit",
"api-utils"
],
"version": "1.3",
"version": "1.4",
"fullName": "Copy ShortURL",
"id": "jid0-ODIKJS9b4IT3H1NYlPKr0NDtLuE",
"name": "copy-shorturl"
Expand Down

0 comments on commit a6ed22d

Please sign in to comment.