Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/ui.js

Issue 11165026: Show notifications on startup (Closed)
Patch Set: Address remaining issue Created July 20, 2013, 10:53 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/notification.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/ui.js
===================================================================
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -29,6 +29,7 @@
let {Subscription, SpecialSubscription, DownloadableSubscription} = require("subscriptionClasses");
let {Synchronizer} = require("synchronizer");
let {KeySelector} = require("keySelector");
+let {Notification} = require("notification");
/**
* Filter corresponding with "disable on site" menu item (set in fillIconMent()).
@@ -264,6 +265,12 @@
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference])
}
+/**
+ * Timer used to delay notification handling.
+ * @type nsITimer
+ */
+let notificationTimer = null;
+
let UI = exports.UI =
{
/**
@@ -420,6 +427,11 @@
if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(action) || action == "load")
this.updateState();
}.bind(this));
+
+ notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ notificationTimer.initWithCallback(this._showNextNotification.bind(this),
+ 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT);
+ onShutdown.add(function() notificationTimer.cancel());
},
/**
@@ -1914,6 +1926,77 @@
if (button)
button.hidden = true;
}
+ },
+
+ _showNextNotification: function(notification)
+ {
+ let window = null;
+ for (window in this.applicationWindows)
+ break;
+
+ if (!window)
+ return;
+
+ let button = window.document.getElementById("abp-toolbarbutton")
+ || window.document.getElementById("abp-status");
+ if (!button)
+ return;
+
+ let notification = Notification.getNextToShow();
+ if (!notification)
+ return;
+
+ this._showNotification(window, button, notification);
+ },
+
+ _showNotification: function(window, button, notification)
+ {
+ function insertMessage(element, text, links)
+ {
+ let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text);
+ if (!match)
+ {
+ element.appendChild(window.document.createTextNode(text));
+ return;
+ }
+
+ let [_, before, tagName, value, after] = match;
+
+ insertMessage(element, before, links);
+
+ let newElement = window.document.createElementNS("http://www.w3.org/1999/xhtml", tagName);
+ if (tagName === "a" && links && links.length)
+ newElement.setAttribute("href", links.shift());
+ insertMessage(newElement, value, links);
+ element.appendChild(newElement);
+
+ insertMessage(element, after, links);
+ }
+
+ let texts = Notification.getLocalizedTexts(notification);
+ let titleElement = window.document.getElementById("abp-notification-title");
+ titleElement.setAttribute("value", texts.title);
+ let messageElement = window.document.getElementById("abp-notification-message");
+ let docLinks = [];
+ for each (let link in notification.links)
+ docLinks.push(Utils.getDocLink(link));
+ insertMessage(messageElement, texts.message, docLinks);
+
+ let links = window.document.querySelectorAll("#abp-notification-message a");
+ for each (let link in links)
+ {
+ let url = link.href;
+ let ui = this;
+ link.onclick = function(event)
+ {
+ event.preventDefault();
+ event.stopPropagation();
+ ui.loadInBrowser(url, window);
+ };
+ }
+
+ let panel = window.document.getElementById("abp-notification");
+ panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null);
}
};
UI.onPopupShowing = UI.onPopupShowing.bind(UI);
« no previous file with comments | « lib/notification.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld