| Index: background.js |
| =================================================================== |
| --- a/background.js |
| +++ b/background.js |
| @@ -59,14 +59,21 @@ |
| function init() |
| { |
| - var filtersLoaded = false; |
| - var prefsLoaded = false; |
| + var filtersLoaded = new Promise(function(resolve) |
| + { |
| + function onFilterAction(action) |
| + { |
| + if (action == "load") |
| + { |
| + FilterNotifier.removeListener(onFilterAction); |
| + resolve(); |
| + } |
| + } |
| + FilterNotifier.addListener(onFilterAction); |
| + }); |
| - var checkLoaded = function() |
| + function onLoaded() |
| { |
| - if (!filtersLoaded || !prefsLoaded) |
| - return; |
| - |
| var info = require("info"); |
| var previousVersion = Prefs.currentVersion; |
| @@ -95,27 +102,9 @@ |
| refreshIconAndContextMenuForAllPages(); |
| }); |
| refreshIconAndContextMenuForAllPages(); |
| - }; |
| + } |
| - var onFilterAction = function(action) |
| - { |
| - if (action == "load") |
| - { |
| - FilterNotifier.removeListener(onFilterAction); |
| - filtersLoaded = true; |
| - checkLoaded(); |
| - } |
| - }; |
| - |
| - var onPrefsLoaded = function() |
| - { |
| - Prefs.onLoaded.removeListener(onPrefsLoaded); |
| - prefsLoaded = true; |
| - checkLoaded(); |
| - }; |
| - |
| - FilterNotifier.addListener(onFilterAction); |
| - Prefs.onLoaded.addListener(onPrefsLoaded); |
| + Promise.all([filtersLoaded, Prefs.isLoaded]).then(onLoaded); |
| } |
| init(); |