You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. /*******************************************************************************
  2. uMatrix - a browser extension to black/white list requests.
  3. Copyright (C) 2017 Raymond Hill
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see {http://www.gnu.org/licenses/}.
  14. Home: https://github.com/gorhill/uMatrix
  15. */
  16. // For background page
  17. 'use strict';
  18. /******************************************************************************/
  19. (function() {
  20. let µm = µMatrix;
  21. let migrateAll = function(callback) {
  22. let mustRestart = false;
  23. let migrateKeyValue = function(details, callback) {
  24. let bin = {};
  25. bin[details.key] = JSON.parse(details.value);
  26. self.browser.storage.local.set(bin, callback);
  27. mustRestart = true;
  28. };
  29. let migrateNext = function() {
  30. self.browser.runtime.sendMessage({ what: 'webext:storageMigrateNext' }, response => {
  31. if ( response.key === undefined ) {
  32. if ( mustRestart ) {
  33. self.browser.runtime.reload();
  34. } else {
  35. callback();
  36. }
  37. return;
  38. }
  39. migrateKeyValue(response, migrateNext);
  40. });
  41. };
  42. self.browser.storage.local.get('legacyStorageMigrated', bin => {
  43. if ( bin && bin.legacyStorageMigrated ) {
  44. self.browser.runtime.sendMessage({ what: 'webext:storageMigrateDone' });
  45. return callback();
  46. }
  47. self.browser.storage.local.set({ legacyStorageMigrated: true });
  48. migrateNext();
  49. });
  50. };
  51. µm.onBeforeStartQueue.push(migrateAll);
  52. })();
  53. /******************************************************************************/