Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -54,29 +54,28 @@ RegExpFilter.typeMap.OBJECT_SUBREQUEST = |
RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OTHER; |
// Chrome on Linux does not fully support chrome.notifications until version 35 |
// https://code.google.com/p/chromium/issues/detail?id=291485 |
var canUseChromeNotifications = require("info").platform == "chromium" |
&& "notifications" in chrome |
&& (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").applicationVersion) > 34); |
-var isFirstRun = false; |
var seenDataCorruption = false; |
require("filterNotifier").FilterNotifier.addListener(function(action) |
{ |
if (action == "load") |
{ |
var importingOldData = importOldData(); |
Thomas Greiner
2014/04/15 12:53:07
Since we can now distinguish first-run from update
Wladimir Palant
2014/04/15 13:31:53
I'd rather not polish this code, it isn't worth th
|
var addonVersion = require("info").addonVersion; |
var prevVersion = ext.storage.currentVersion; |
- if (prevVersion != addonVersion) |
+ if (prevVersion != addonVersion || FilterStorage.firstRun) |
{ |
- isFirstRun = !prevVersion; |
+ seenDataCorruption = prevVersion && FilterStorage.firstRun; |
ext.storage.currentVersion = addonVersion; |
if (!importingOldData) |
addSubscription(prevVersion); |
} |
if (canUseChromeNotifications) |
initChromeNotifications(); |
initAntiAdblockNotification(); |
@@ -316,17 +315,17 @@ function prepareNotificationIconAndPopup |
if (animateIcon) |
iconAnimation.stop(); |
notificationClosed(); |
}; |
if (animateIcon) |
iconAnimation.update(activeNotification.type); |
} |
-function openNotificationLinks() |
+function openNotificationLinks() |
{ |
if (activeNotification.links) |
{ |
activeNotification.links.forEach(function(link) |
{ |
ext.windows.getLastFocused(function(win) |
{ |
win.openTab(Utils.getDocLink(link)); |
@@ -396,35 +395,35 @@ function initChromeNotifications() |
chrome.notifications.onClicked.addListener(clearActiveNotification); |
chrome.notifications.onClosed.addListener(notificationClosed); |
} |
function showNotification(notification) |
{ |
if (activeNotification && activeNotification.id === notification.id) |
return; |
- |
+ |
activeNotification = notification; |
if (activeNotification.type === "critical" || activeNotification.type === "question") |
{ |
var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
if (hasWebkitNotifications && "createHTMLNotification" in webkitNotifications) |
{ |
var notification = webkitNotifications.createHTMLNotification("notification.html"); |
notification.show(); |
prepareNotificationIconAndPopup(); |
return; |
} |
- |
+ |
var texts = Notification.getLocalizedTexts(notification); |
var title = texts.title || ""; |
var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
var iconUrl = ext.getURL("icons/abp-128.png"); |
var hasLinks = activeNotification.links && activeNotification.links.length > 0; |
- |
+ |
if (canUseChromeNotifications) |
{ |
var opts = { |
type: "basic", |
title: title, |
message: message, |
buttons: [], |
priority: 2 // We use the highest priority to prevent the notification from closing automatically |
@@ -437,17 +436,17 @@ function showNotification(notification) |
else |
{ |
var regex = /<a>(.*?)<\/a>/g; |
var plainMessage = texts.message || ""; |
var match; |
while (match = regex.exec(plainMessage)) |
opts.buttons.push({title: match[1]}); |
} |
- |
+ |
imgToBase64(iconUrl, function(iconData) |
{ |
opts["iconUrl"] = iconData; |
chrome.notifications.create("", opts, function() {}); |
}); |
} |
else if (hasWebkitNotifications && "createNotification" in webkitNotifications && activeNotification.type !== "question") |
{ |
@@ -462,17 +461,17 @@ function showNotification(notification) |
notification.addEventListener("close", notificationClosed, false); |
}); |
} |
else |
{ |
var message = title + "\n" + message; |
if (hasLinks) |
message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
- |
+ |
var approved = confirm(message); |
if (activeNotification.type === "question") |
notificationButtonClick(approved ? 0 : 1); |
else if (approved) |
openNotificationLinks(); |
} |
} |
prepareNotificationIconAndPopup(); |