Multiple fixes for chrome app

This commit is contained in:
Matias Pando 2014-12-02 10:40:24 -03:00
commit 834c57a51a
12 changed files with 88 additions and 10 deletions

View file

@ -4,19 +4,67 @@ var copay = require('copay');
var _ = require('lodash');
var config = defaultConfig;
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
var localStorage;
if (window.chrome && chrome.runtime && chrome.runtime.id) {
console.log('Is a chrome app!');
if (isChromeApp) {
var storage = chrome.storage.local;
var myAccess = 'myAccess';
var obj = {};
obj[myAccess] = Math.floor((Math.random() * 1000) + 1);;
storage.get(myAccess, function(result) {
console.log('Last access 1', JSON.stringify(myAccess), JSON.stringify(result));
});
storage.set(obj);
storage.get(myAccess, function(result) {
console.log('Last access 2', JSON.stringify(myAccess), JSON.stringify(result));
});
console.log('Is a chrome app!...app.js');
console.log('chrome.storage', chrome.storage);
chrome.storage.local.set({
'MiNombre': 'Matias'
}, function(done) {
console.log('Saving to local storage', done);
});
localStorage = chrome.storage.local;
console.log('localStorage', localStorage);
} else {
console.log('Is web!');
localStorage = window.localStorage;
}
console.log('access to localStorage');
var localConfig;
if (localStorage) {
localConfig = JSON.parse(localStorage.getItem('config'));
if (isChromeApp) {
var result;
localStorage.getItem('config', function(data) {
result = data;
});
console.log('retrieving data from local storage', result);
localConfig = JSON.parse(result);
} else {
localConfig = JSON.parse(localStorage.getItem('config'));
console.log('localStorage', localConfig);
}
} else {
console.log('localStorage is null ');
}

View file

@ -12,7 +12,7 @@ angular.module('copayApp.controllers').controller('SettingsController', function
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
if (isChromeApp) {
console.log('Is a chrome app!');
console.log('Is a chrome app!...settings.js');
localStorage = chrome.storage.local;
} else {
console.log('Is web!');
@ -92,6 +92,7 @@ angular.module('copayApp.controllers').controller('SettingsController', function
plugins[$scope.selectedStorage.pluginName] = true;
copay.logger.setLevel($scope.selectedLogLevel.name);
localstorageService.setItem('config', JSON.stringify({
network: insightSettings,
version: copay.version,
@ -107,6 +108,7 @@ angular.module('copayApp.controllers').controller('SettingsController', function
}), function() {
applicationService.restart();
});
};

View file

@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('UnsupportedController',
var localStorage;
if (window.chrome && chrome.runtime && chrome.runtime.id) {
console.log('Is a chrome app!');
console.log('Is a chrome app!..unssoported.js');
localStorage = chrome.storage.local;
} else {
console.log('Is web!');

View file

@ -76,6 +76,15 @@ Compatibility._decrypt = function(base64, passphrase) {
Compatibility._read = function(k, passphrase, cb) {
preconditions.checkArgument(cb);
var localStorage;
if (window.chrome && chrome.runtime && chrome.runtime.id) {
console.log('Is a chrome app!..Compatibility.js');
localStorage = chrome.storage.local;
} else {
console.log('Is web!');
localStorage = window.localStorage;
}
var ret = localStorage.getItem(k);
if (!ret) return cb(null);
var ret = self._decrypt(ret, passphrase);

View file

@ -7,6 +7,7 @@ var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
function LocalStorage() {
this.type = 'DB';
if (isChromeApp) {
localStorage = chrome.storage.local;
window.localStorage = chrome.storage.local;

View file

@ -119,12 +119,14 @@ angular
}
$rootScope.$on('$routeChangeStart', function(event, next, current) {
var localStorage;
if (window.chrome && chrome.runtime && chrome.runtime.id) {
console.log('Is a chrome app!');
console.log('Is a chrome app!...routes.js');
console.log('chrome.storage', chrome.storage);
console.log('chrome.storage.local', chrome.storage.local);
localStorage = chrome.storage.local;
console.log('chrome.storage', chrome.storage);
console.log('localStorage', localStorage);
} else {
console.log('Is web!');

View file

@ -6,7 +6,7 @@ factory('notification', ['$timeout',
var localStorage;
if (window.chrome && chrome.runtime && chrome.runtime.id) {
console.log('Is a chrome app!');
console.log('Is a chrome app!...notification.js');
localStorage = chrome.storage.local;
} else {
console.log('Is web!');