diff --git a/lib/main.js b/lib/main.js index 1b52815..16d327c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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 */ @@ -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']; diff --git a/lib/simple-notify.js b/lib/simple-notify.js index e7b4ca1..d1c54b1 100644 --- a/lib/simple-notify.js +++ b/lib/simple-notify.js @@ -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', @@ -26,7 +26,7 @@ function notify(txt) { // Box only case 1: - boxNotify(txt, win); + boxNotify(txt); break; // Growl with box fallback @@ -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. */ @@ -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; } diff --git a/package.json b/package.json index 13adc56..32c04b1 100644 --- a/package.json +++ b/package.json @@ -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 ", "dependencies": [ - "jetpack-core" + "addon-kit", + "api-utils" ], - "version": "1.3", + "version": "1.4", "fullName": "Copy ShortURL", "id": "jid0-ODIKJS9b4IT3H1NYlPKr0NDtLuE", "name": "copy-shorturl"