From 889768b6edece4d26b7acc8e0d5d5814b897342e Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 24 Aug 2017 15:16:40 +0200 Subject: [PATCH] move chromeCloudStorageSync away from app.js --- src/app.js | 56 ++----------------------- src/app/files/chromeCloudStorageSync.js | 50 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 src/app/files/chromeCloudStorageSync.js diff --git a/src/app.js b/src/app.js index d8e19a4fd1..bd3b1f4720 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,3 @@ -/* global confirm, chrome */ 'use strict' var async = require('async') @@ -16,6 +15,7 @@ var QueryParams = require('./lib/query-params') var GistHandler = require('./lib/gist-handler') var Storage = require('./storage') var Browserfiles = require('./app/files/browser-files') +var chromeCloudStorageSync = require('./app/files/chromeCloudStorageSync') var SharedFolder = require('./app/files/shared-folder') var Config = require('./config') var Editor = require('./app/editor/editor') @@ -277,58 +277,8 @@ function run () { } } - // ----------------- Chrome cloud storage sync -------------------- - - function chromeCloudSync () { - if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) { - return - } - - var obj = {} - var done = false - var count = 0 - - function check (key) { - chrome.storage.sync.get(key, function (resp) { - console.log('comparing to cloud', key, resp) - if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && confirm('Overwrite "' + key + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) { - console.log('Overwriting', key) - filesProviders['browser'].set(key, resp[key]) - } else { - console.log('add to obj', obj, key) - filesProviders['browser'].get(key, (error, content) => { - if (error) { - console.log(error) - } else { - obj[key] = content - } - }) - } - done++ - if (done >= count) { - chrome.storage.sync.set(obj, function () { - console.log('updated cloud files with: ', obj, this, arguments) - }) - } - }) - } - - for (var y in filesProviders['browser'].list()) { - console.log('checking', y) - filesProviders['browser'].get(y, (error, content) => { - if (error) { - console.log(error) - } else { - obj[y] = content - count++ - check(y) - } - }) - } - } - - window.syncStorage = chromeCloudSync - chromeCloudSync() + window.syncStorage = chromeCloudStorageSync + chromeCloudStorageSync() // ---------------- FilePanel -------------------- var FilePanelAPI = { diff --git a/src/app/files/chromeCloudStorageSync.js b/src/app/files/chromeCloudStorageSync.js new file mode 100644 index 0000000000..428b4c4bdd --- /dev/null +++ b/src/app/files/chromeCloudStorageSync.js @@ -0,0 +1,50 @@ +/* global confirm, chrome */ +'use strict' + +module.exports = function (filesProviders) { + if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) { + return + } + + var obj = {} + var done = false + var count = 0 + + function check (key) { + chrome.storage.sync.get(key, function (resp) { + console.log('comparing to cloud', key, resp) + if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && confirm('Overwrite "' + key + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) { + console.log('Overwriting', key) + filesProviders['browser'].set(key, resp[key]) + } else { + console.log('add to obj', obj, key) + filesProviders['browser'].get(key, (error, content) => { + if (error) { + console.log(error) + } else { + obj[key] = content + } + }) + } + done++ + if (done >= count) { + chrome.storage.sync.set(obj, function () { + console.log('updated cloud files with: ', obj, this, arguments) + }) + } + }) + } + + for (var y in filesProviders['browser'].list()) { + console.log('checking', y) + filesProviders['browser'].get(y, (error, content) => { + if (error) { + console.log(error) + } else { + obj[y] = content + count++ + check(y) + } + }) + } +}