@ -1,4 +1,4 @@
/* global alert, confirm, prompt, Option, Worker */
/* global alert, confirm, prompt, Option, Worker, chrome */
'use strict'
'use strict'
var $ = require ( 'jquery' )
var $ = require ( 'jquery' )
@ -39,7 +39,7 @@ window.addEventListener('message', function (ev) {
var run = function ( ) {
var run = function ( ) {
var self = this
var self = this
this . event = new EventManager ( )
this . event = new EventManager ( )
var storage = new Storage ( updateFiles )
var storage = new Storage ( )
function loadFiles ( files ) {
function loadFiles ( files ) {
for ( var f in files ) {
for ( var f in files ) {
@ -84,10 +84,50 @@ var run = function () {
} )
} )
} )
} )
// ----------------- storage sync --------------------
// ----------------- Chrome cloud storage sync --------------------
window . syncStorage = storage . sync
function chromeCloudSync ( ) {
storage . sync ( )
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 ----------------------
// ----------------- editor ----------------------
@ -656,8 +696,6 @@ var run = function () {
loadVersion ( 'builtin' )
loadVersion ( 'builtin' )
} )
} )
storage . sync ( )
}
}
module . exports = {
module . exports = {