start.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*******************************************************************************
  2. ηMatrix - a browser extension to black/white list requests.
  3. Copyright (C) 2014-2019 Raymond Hill
  4. Copyright (C) 2019-2022 Alessio Vanni
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program 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. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see {http://www.gnu.org/licenses/}.
  15. Home: https://gitlab.com/vannilla/ematrix
  16. uMatrix Home: https://github.com/gorhill/uMatrix
  17. */
  18. 'use strict';
  19. // ORDER IS IMPORTANT
  20. // Load everything
  21. (function() {
  22. let ηm = ηMatrix;
  23. let processCallbackQueue = function (queue, callback) {
  24. while (queue.length > 0) {
  25. let fn = queue.pop();
  26. fn();
  27. }
  28. if (typeof callback === 'function') {
  29. callback();
  30. }
  31. };
  32. let onAllDone = function () {
  33. ηm.webRequest.start();
  34. ηm.assets.checkVersion();
  35. ηm.assets.addObserver(ηm.assetObserver.bind(ηm));
  36. ηm.scheduleAssetUpdater(ηm.userSettings.autoUpdate ? 7 * 60 * 1000 : 0);
  37. vAPI.cloud.start([ 'myRulesPane' ]);
  38. };
  39. let onTabsReady = function (tabs) {
  40. for (let i=tabs.length-1; i>=0; --i) {
  41. // console.debug('start.js > binding %d tabs', i);
  42. let tab = tabs[i];
  43. ηm.tabContextManager.push(tab.id, tab.url, 'newURL');
  44. }
  45. onAllDone();
  46. };
  47. let onUserSettingsLoaded = function () {
  48. ηm.loadHostsFiles();
  49. };
  50. let onPSLReady = function () {
  51. ηm.loadUserSettings(onUserSettingsLoaded);
  52. ηm.loadRawSettings();
  53. ηm.loadMatrix();
  54. // rhill 2013-11-24: bind behind-the-scene virtual tab/url
  55. // manually, since the normal way forbid binding behind the
  56. // scene tab.
  57. // https://github.com/gorhill/httpswitchboard/issues/67
  58. ηm.pageStores[vAPI.noTabId] =
  59. ηm.pageStoreFactory(ηm.tabContextManager.mustLookup(vAPI.noTabId));
  60. ηm.pageStores[vAPI.noTabId].title =
  61. vAPI.i18n('statsPageDetailedBehindTheScenePage');
  62. vAPI.tabs.getAll(onTabsReady);
  63. };
  64. processCallbackQueue(ηm.onBeforeStartQueue, function () {
  65. ηm.loadPublicSuffixList(onPSLReady);
  66. });
  67. })();