This commit is contained in:
Mavis Ou 2013-05-30 18:02:30 -07:00
Родитель 20107bfe6f
Коммит d27b4901e6
4 изменённых файлов: 27 добавлений и 19 удалений

Просмотреть файл

@ -17,8 +17,9 @@ self.port.on('connection', function(connection){
}
});
self.port.on('init', function(){
// TODO: handle(save) storage.connections
self.port.on('init', function(collusionToken){
localStorage.collusionToken = collusionToken;
if (unsafeWindow && unsafeWindow.currentVisualization){
if ( localStorage.connections ){
unsafeWindow.allConnections = JSON.parse(localStorage.connections);

Просмотреть файл

@ -71,11 +71,8 @@ window.addEventListener("DOMContentLoaded", function(){
});
document.querySelector(".download").addEventListener('click', function() {
addon.once('export-data', function(connections){
console.log('received export data');
window.open('data:application/json,' + connections);
});
addon.emit('export');
window.open('data:application/json,' + exportFormat(allConnections));
});
document.querySelector('.reset-data').addEventListener('click', function(){
@ -440,3 +437,17 @@ document.querySelector('#content').addEventListener('click', function(event){
}
},false);
/* Export ========== */
function exportFormat(connections){
// if (!lastSync){
// lastSync = 0;
// }
return JSON.stringify({
format: 'Collusion Save File',
version: '1.1',
token: localStorage.collusionToken,
connections: connections
});
}

Просмотреть файл

@ -23,6 +23,7 @@ exports.exportFormat = exportFormat;
// FIXME: Move persistence into a component
/* BEGIN FLAG PERSISTENCE */
var restored = false;
var ss = require('simple-storage');
var storage = ss.storage;
function restore(){
@ -36,12 +37,10 @@ function restore(){
}else{
Connection.emit("tempConnections", []);
}
restored = true;
if (!storage.collusionToken){
storage.collusionToken = require('sdk/util/uuid').uuid().toString();
}
console.error('restored %s logs, %s objects', Connection.restoredLogs, Connection.restoredObjects);
}
function reset(){
@ -49,7 +48,7 @@ function reset(){
storage.tempConnections.length = 0;
}
}
var collusionToken = storage.collusionToken;
console.log('Current capacity is %s% of quota', Math.round(ss.quotaUsage * 100));
/* END FLAG PERSISTENCE */
@ -427,4 +426,6 @@ function exportFormat(connections, lastSync){
});
}
/* END FLAG SERIALIZATION */
/* BEGIN FLAG PERSISTENCE */
if (!restored) restore();
/* END FLAG PERSISTENCE */

Просмотреть файл

@ -101,7 +101,7 @@ function attachToCollusionPage(worker) {
}
Connection.emit("toggleStore", false);
worker.port.emit('log', 'Connection received restored');
worker.port.emit('init');
worker.port.emit('init', require('sdk/util/uuid').uuid().toString());
};
var onTempConnections = function(tempConn){
@ -131,11 +131,6 @@ function attachToCollusionPage(worker) {
Connection.on('connection', onConnection);
worker.port.on('export', function(){
worker.port.emit('log', 'exporting data from addon');
worker.port.emit('export-data', exportFormat());
});
worker.port.on('startUpload', function(){
Connection.emit('startUpload');
});