[Pkg-mozext-commits] [tabmixplus] 15/48: Save backup of the storage.js file to webext at tabmixplus.org folder for the case we will use it as the new extension id

David Prévot taffit at moszumanska.debian.org
Sun Aug 20 03:14:35 UTC 2017


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit acbbd6bce8fa2ca676f30d28201e8506898fb1ef
Author: onemen <tabmix.onemen at gmail.com>
Date:   Wed Aug 9 13:52:22 2017 +0300

    Save backup of the storage.js file to webext at tabmixplus.org folder for the case we will use it as the new extension id
---
 modules/extensions/EmbeddedWebExtension.jsm | 32 ++++++++++++++++++++++++++---
 webextension/background.js                  |  9 +++++++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/modules/extensions/EmbeddedWebExtension.jsm b/modules/extensions/EmbeddedWebExtension.jsm
index bb2936a..f4f2255 100644
--- a/modules/extensions/EmbeddedWebExtension.jsm
+++ b/modules/extensions/EmbeddedWebExtension.jsm
@@ -9,6 +9,10 @@ Cu.import('resource://gre/modules/XPCOMUtils.jsm', this);
 XPCOMUtils.defineLazyModuleGetter(this, 'Services',
   'resource://gre/modules/Services.jsm');
 
+XPCOMUtils.defineLazyGetter(this, "OS", () => {
+  return Cu.import("resource://gre/modules/osfile.jsm", {}).OS;
+});
+
 XPCOMUtils.defineLazyModuleGetter(this, 'TabmixSvc',
   'resource://tabmixplus/TabmixSvc.jsm');
 
@@ -147,6 +151,10 @@ this.EmbeddedWebExtension = {
       throw new Error('Unexpected messageID: ' + ID);
     }
 
+    if (message.saveBackup) {
+      this.saveBackupFile();
+    }
+
     if (message.error) {
       // Unexpectedly, an error occurred.
       TabmixSvc.console.reportError(message.error);
@@ -232,11 +240,11 @@ this.EmbeddedWebExtension = {
 
     if (this.hashList) {
       const data = this.getCurrentSessionsData(this.hashList);
-      this.sendSessionToStorage(data);
+      this.sendSessionToStorage(data, shutDown);
     } else {
       this.getCurrentHashList()
           .then(result => this.getCurrentSessionsData(result || []))
-          .then(data => this.sendSessionToStorage(data))
+          .then(data => this.sendSessionToStorage(data, shutDown))
           .catch(err => TabmixSvc.console.reportError(err));
     }
   },
@@ -297,7 +305,7 @@ this.EmbeddedWebExtension = {
     return strings[0] + count + strings[1];
   },
 
-  sendSessionToStorage({currentHashList, newHashList, sessionsData}) {
+  sendSessionToStorage({currentHashList, newHashList, sessionsData}, saveBackup) {
     let remove, add;
     const hashToRemove = currentHashList.filter(hash => !newHashList.includes(hash));
 
@@ -323,12 +331,30 @@ this.EmbeddedWebExtension = {
       this.handleStorageRequest({
         messageID: 'migration.sessions',
         type: 'update',
+        saveBackup,
         remove,
         add,
       });
+    } else if (saveBackup) {
+      this.saveBackupFile();
     }
   },
 
+  // save backup of the storage.js file to webext at tabmixplus.org folder
+  // for the case we will use it as the new extension id
+  saveBackupFile() {
+    const dataFolder = OS.Path.join(OS.Constants.Path.profileDir, "browser-extension-data");
+    const storage = OS.Path.join(dataFolder, TABMIX_ID, "storage.js");
+    const backupFolder = OS.Path.join(dataFolder, "webext at tabmixplus.org");
+    const backupFile = OS.Path.join(backupFolder, "storage.js");
+
+    // since we are here only when browser-extension-data exist, we only need to
+    // create our backup folder
+    OS.File.makeDir(backupFolder).then(() => {
+      return OS.File.copy(storage, backupFile);
+    }).catch(error => TabmixSvc.console.reportError(error));
+  },
+
   _lastSaveTime: 0,
 
   _currentHash: null,
diff --git a/webextension/background.js b/webextension/background.js
index ec33bc6..084a4c6 100644
--- a/webextension/background.js
+++ b/webextension/background.js
@@ -5,7 +5,7 @@ const MIGRATE = 'tabmix.session.migrate.';
 const port = browser.runtime.connect({name: 'tabmix-storage-port'});
 
 function updateSessionsData(message) {
-  const {add, remove} = message;
+  const {add, remove, messageID, saveBackup} = message;
   const asyncResult = [Promise.resolve()];
 
   if (remove) {
@@ -17,6 +17,13 @@ function updateSessionsData(message) {
     add.messageID = message.messageID + '.add';
     asyncResult.push(storageMethods('set', add));
   }
+
+  if (saveBackup) {
+    const postMessage = () => {
+      port.postMessage({messageID, saveBackup});
+    };
+    Promise.all(asyncResult).then(postMessage).catch(postMessage);
+  }
 }
 
 function getHashList({messageID}) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list