import storage, { Storage } from '../../utils/storage';

class CES {
  constructor () {
    this.modules = [];
    this.hasMigratedKey = 'is-sync';
  }

  registerModule (Module) {
    this.modules.push(new Module());
  }

  init () {
    storage.get(this.hasMigratedKey)
    .catch(() => this.migrateStorage())
    .then(() => this.initModules());
  }

  initModules () {
    this.modules.forEach(module => {
      module.shouldInit() && module.go();
    });
  }

  migrateStorage () {
    // The extension used to use the local storagearea,
    // this moves everything from local to sync and
    // clears local.
    const local = new Storage('local');
    local.get().then(response => {
      response[this.hasMigratedKey] = true;
      storage.set(response);
      chrome.storage.local.clear();
    });
  }
}

export default new CES();

@@ -653,16 +653,23 @@
 ');%0A    
+return 
 local.ge
@@ -741,24 +741,31 @@
 ;%0A      
+chrome.
 storage.
 set(resp
@@ -760,20 +760,20 @@
 age.
-set(response
+local.clear(
 );%0A 
@@ -773,39 +773,39 @@
 ar();%0A      
-chrome.
+return 
 storage.
 local.clear(
@@ -788,36 +788,36 @@
 urn storage.
-local.clear(
+set(response
 );%0A    %7D);%0A 

Fix promise return