move chromeCloudStorageSync away from app.js

pull/1/head
yann300 7 years ago
parent 8a35c251ae
commit 889768b6ed
  1. 56
      src/app.js
  2. 50
      src/app/files/chromeCloudStorageSync.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 = {

@ -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)
}
})
}
}
Loading…
Cancel
Save