Index: adblockplus/Api.jsm |
=================================================================== |
--- a/adblockplus/Api.jsm |
+++ b/adblockplus/Api.jsm |
@@ -40,39 +40,44 @@ let {Filter, RegExpFilter} = require("fi |
let {FilterNotifier} = require("filterNotifier"); |
let {FilterStorage} = require("filterStorage"); |
let {defaultMatcher} = require("matcher"); |
let {Prefs} = require("prefs"); |
let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscription, ExternalSubscription} = require("subscriptionClasses"); |
let {Synchronizer} = require("synchronizer"); |
let {UI} = require("ui"); |
-let subscriptionsSavedPref = "subscriptions_saved"; |
+const SUBSCRIPTIONS_SAVED_PREF = "subscriptions_saved"; |
+const USER_REMOVED_BLOCK_SUBS_PREF = "user_removed_block_subscriptions"; |
function initFilterListeners() |
{ |
FilterNotifier.on("load", onFiltersLoad); |
FilterNotifier.on("save", onFiltersSave); |
} |
function onFiltersLoad() |
{ |
let {addonVersion} = require("info"); |
- if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPref)) |
+ let detectedSubscriptionFailure = !hasBlockSubscription() && |
+ (!getBoolPref(SUBSCRIPTIONS_SAVED_PREF) || !getBoolPref(USER_REMOVED_BLOCK_SUBS_PREF) || FilterStorage.loadFromDiskFailed); |
+ |
+ // We will only try to recover the default subscription settings if the addonVersion hasn't changed, |
+ // otherwise it will be handled in firstRunActions(), inside ui.js |
+ if(Prefs.currentVersion == addonVersion && detectedSubscriptionFailure) |
anton
2017/12/04 14:00:46
space is needed here
diegocarloslima
2017/12/05 09:44:10
Acknowledged.
|
{ |
- UI.addSubscription(UI.currentWindow, Prefs.currentVersion); |
+ UI.addSubscription(UI.currentWindow, "0.0"); |
} |
Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); |
} |
- |
function onFiltersSave() |
{ |
- if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl)) |
+ if (hasBlockSubscription()) |
{ |
- setBoolPref(subscriptionsSavedPref, true); |
+ setBoolPref(SUBSCRIPTIONS_SAVED_PREF, true); |
} |
Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); |
} |
function getBoolPref(name) |
{ |
let branch = getPrefsBranch(); |
try |
@@ -94,16 +99,22 @@ function setBoolPref(name, value) |
function getPrefsBranch() |
{ |
let {addonRoot, addonName} = require("info"); |
let branchName = "extensions." + addonName + "."; |
return Services.prefs.getBranch(branchName); |
} |
+function hasBlockSubscription() |
+{ |
+ return FilterStorage.subscriptions.some( |
+ (subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl); |
jens
2017/12/04 11:00:30
Do we need parentheses when there's only one param
diegocarloslima
2017/12/05 09:44:09
Acknowledged.
|
+} |
+ |
function getWhitelistingFilter(url) |
{ |
let uriObject = Services.io.newURI(url, null, null); |
try |
{ |
return defaultMatcher.whitelist.matchesAny( |
uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null, false); |
} |
@@ -164,21 +175,28 @@ var AdblockPlusApi = |
if (subscription) |
{ |
subscription.disabled = false; |
if (!subscription.lastDownload) |
{ |
Synchronizer.execute(subscription); |
} |
} |
+ if (hasBlockSubscription()) |
+ { |
+ setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, false); |
+ } |
}, |
removeSubscription: function(url) |
{ |
- FilterStorage.removeSubscription( |
- FilterStorage.knownSubscriptions[url]); |
+ FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[url]); |
+ if (!hasBlockSubscription()) |
+ { |
+ setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, true); |
+ } |
}, |
getActiveSubscriptions: function() |
{ |
let subscriptions = []; |
for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
{ |
let subscription = FilterStorage.subscriptions[i]; |
if (!subscription.disabled) |