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

Side by Side Diff: lib/notification.js

Issue 11175021: Add Notification module (Closed)
Patch Set: Created July 18, 2013, 12:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /**
19 * @fileOverview Handles notifications.
20 */
21
22 Cu.import("resource://gre/modules/Services.jsm");
23
24 let {Prefs} = require("prefs");
25
26 function compareSeverity(notification1, notification2)
27 {
28 let levels = {information: 0, critical: 1};
29 return levels[notification1.severity] - levels[notification2.severity];
30 }
31
32 /**
33 * Regularly fetches notifications and decides which to show.
34 * @class
35 */
36 let Notification = exports.Notification =
37 {
38 /**
39 * Determines which notification is to be shown next.
40 * @param {Array of Object} notifications active notifications
41 * @return {Object} notification to be shown, or null if there is none
42 */
43 getNextToShow: function(notifications)
44 {
45 if (!Prefs.shownNotifications)
46 Prefs.shownNotifications = [];
47
48 let notificationToShow;
49 for each (let notification in notifications)
50 {
51 if (notification.severity === "information"
52 && Prefs.shownNotifications.indexOf(notification.timestamp) !== -1)
53 continue;
54
55 let info = require("info");
56 let platform = info.application;
57 let version = info.addonVersion;
58
59 if ("platforms" in notification
60 && notification.platforms.indexOf("chrome") === -1)
61 continue;
62
63 if ("minVersion" in notification
64 && Services.vc.compare(version, notification.minVersion) < 0)
65 continue;
66
67 if ("maxVersion" in notification
68 && Services.vc.compare(version, notification.maxVersion) > 0)
69 continue;
70
71 if (!notificationToShow
72 || compareSeverity(notification, notificationToShow) > 0)
73 notificationToShow = notification;
74 }
75
76 if (notificationToShow && "timestamp" in notificationToShow)
77 Prefs.shownNotifications.push(notificationToShow.timestamp);
78
79 return notificationToShow;
80 }
81 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld