Merge pull request #373 from ethereum/move-chrome-sync

Move Chrome syncing back to app.js
pull/1/head
chriseth 8 years ago committed by GitHub
commit 8f74793b51
  1. 52
      src/app.js
  2. 43
      src/app/storage.js

@ -1,4 +1,4 @@
/* global alert, confirm, prompt, Option, Worker */
/* global alert, confirm, prompt, Option, Worker, chrome */
'use strict'
var $ = require('jquery')
@ -39,7 +39,7 @@ window.addEventListener('message', function (ev) {
var run = function () {
var self = this
this.event = new EventManager()
var storage = new Storage(updateFiles)
var storage = new Storage()
function loadFiles (files) {
for (var f in files) {
@ -84,10 +84,50 @@ var run = function () {
})
})
// ----------------- storage sync --------------------
// ----------------- Chrome cloud storage sync --------------------
window.syncStorage = storage.sync
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 "' + utils.fileNameFromKey(key) + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) {
console.log('Overwriting', key)
storage.set(key, resp[key])
updateFiles()
} else {
console.log('add to obj', obj, key)
obj[key] = storage.get(key)
}
done++
if (done >= count) {
chrome.storage.sync.set(obj, function () {
console.log('updated cloud files with: ', obj, this, arguments)
})
}
})
}
for (var y in storage.keys()) {
console.log('checking', y)
obj[y] = storage.get(y)
if (!utils.isCachedFile(y)) {
continue
}
count++
check(y)
}
}
window.syncStorage = chromeCloudSync
chromeCloudSync()
// ----------------- editor ----------------------
@ -656,8 +696,6 @@ var run = function () {
loadVersion('builtin')
})
storage.sync()
}
module.exports = {

@ -1,9 +1,8 @@
/* global chrome, confirm */
'use strict'
var utils = require('./utils')
function Storage (updateFiles) {
function Storage () {
this.rename = function (originalName, newName) {
var content = this.get(originalName)
this.set(newName, content)
@ -43,46 +42,6 @@ function Storage (updateFiles) {
}
this.set(filename, content)
}
this.sync = function () {
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 "' + utils.fileNameFromKey(key) + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) {
console.log('Overwriting', key)
window.localStorage.setItem(key, resp[key])
updateFiles()
} else {
console.log('add to obj', obj, key)
obj[key] = window.localStorage[key]
}
done++
if (done >= count) {
chrome.storage.sync.set(obj, function () {
console.log('updated cloud files with: ', obj, this, arguments)
})
}
})
}
for (var y in window.localStorage) {
console.log('checking', y)
obj[y] = window.localStorage.getItem(y)
if (!utils.isCachedFile(y)) {
continue
}
count++
check(y)
}
}
}
module.exports = Storage

Loading…
Cancel
Save