chromeStorage fixes
This commit is contained in:
parent
ee025fc80b
commit
5bfbf64778
7 changed files with 44 additions and 143 deletions
8
init.js
8
init.js
|
|
@ -21,15 +21,7 @@ function init() {
|
||||||
} else if (ns6 || ie4) {
|
} else if (ns6 || ie4) {
|
||||||
ld.display = "none";
|
ld.display = "none";
|
||||||
} else {
|
} else {
|
||||||
console.log('Warning!! is a chrome app!');
|
|
||||||
console.log('ns4', ns4);
|
|
||||||
console.log('ns6', ns6);
|
|
||||||
console.log('ie4', ie4);
|
|
||||||
|
|
||||||
ld = document.loading;
|
|
||||||
|
|
||||||
ld = document.getElementById("loading").style;
|
ld = document.getElementById("loading").style;
|
||||||
|
|
||||||
ld.visibility = "hidden";
|
ld.visibility = "hidden";
|
||||||
ld.display = "none";
|
ld.display = "none";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
85
js/app.js
85
js/app.js
|
|
@ -3,82 +3,25 @@
|
||||||
var copay = require('copay');
|
var copay = require('copay');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var config = defaultConfig;
|
var config = defaultConfig;
|
||||||
|
var LS = require('../plugins/LocalStorage');
|
||||||
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
|
var ls = new LS();
|
||||||
|
|
||||||
var localStorage;
|
|
||||||
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;
|
var localConfig;
|
||||||
if (localStorage) {
|
|
||||||
|
|
||||||
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 ');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var defaults = JSON.parse(JSON.stringify(defaultConfig));
|
var defaults = JSON.parse(JSON.stringify(defaultConfig));
|
||||||
|
|
||||||
if (localConfig) {
|
|
||||||
var cmv = copay.version.split('.')[1];
|
ls.getItem('config', function(err, data) {
|
||||||
var lmv = localConfig.version ? localConfig.version.split('.')[1] : '-1';
|
localConfig = JSON.parse(data);
|
||||||
if (cmv === lmv) {
|
if (localConfig) {
|
||||||
_.each(localConfig, function(value, key) {
|
var cmv = copay.version.split('.')[1];
|
||||||
config[key] = value;
|
var lmv = localConfig.version ? localConfig.version.split('.')[1] : '-1';
|
||||||
});
|
if (cmv === lmv) {
|
||||||
|
_.each(localConfig, function(value, key) {
|
||||||
|
config[key] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
var modules = [
|
var modules = [
|
||||||
'ngRoute',
|
'ngRoute',
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,10 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
$scope.insightTestnet = config.network.testnet.url;
|
$scope.insightTestnet = config.network.testnet.url;
|
||||||
$scope.defaultLogLevel = config.logLevel || 'log';
|
$scope.defaultLogLevel = config.logLevel || 'log';
|
||||||
|
|
||||||
|
|
||||||
var localStorage;
|
|
||||||
|
|
||||||
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
|
|
||||||
if (isChromeApp) {
|
|
||||||
console.log('Is a chrome app!...settings.js');
|
|
||||||
localStorage = chrome.storage.local;
|
|
||||||
} else {
|
|
||||||
console.log('Is web!');
|
|
||||||
localStorage = window.localStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
var logLevels = copay.logger.getLevels();
|
var logLevels = copay.logger.getLevels();
|
||||||
|
|
||||||
$scope.availableLogLevels = [];
|
$scope.availableLogLevels = [];
|
||||||
|
|
||||||
|
|
||||||
for (var key in logLevels) {
|
for (var key in logLevels) {
|
||||||
$scope.availableLogLevels.push({
|
$scope.availableLogLevels.push({
|
||||||
'name': key
|
'name': key
|
||||||
|
|
@ -75,7 +62,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
|
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
|
||||||
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
|
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
|
||||||
|
|
||||||
|
|
||||||
var insightSettings = {
|
var insightSettings = {
|
||||||
livenet: {
|
livenet: {
|
||||||
url: $scope.insightLivenet,
|
url: $scope.insightLivenet,
|
||||||
|
|
@ -92,7 +78,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
plugins[$scope.selectedStorage.pluginName] = true;
|
plugins[$scope.selectedStorage.pluginName] = true;
|
||||||
copay.logger.setLevel($scope.selectedLogLevel.name);
|
copay.logger.setLevel($scope.selectedLogLevel.name);
|
||||||
|
|
||||||
|
|
||||||
localstorageService.setItem('config', JSON.stringify({
|
localstorageService.setItem('config', JSON.stringify({
|
||||||
network: insightSettings,
|
network: insightSettings,
|
||||||
version: copay.version,
|
version: copay.version,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
|
||||||
function LocalStorage() {
|
function LocalStorage() {
|
||||||
this.type = 'DB';
|
this.type = 'DB';
|
||||||
|
|
||||||
|
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
localStorage = chrome.storage.local;
|
localStorage = chrome.storage.local;
|
||||||
window.localStorage = chrome.storage.local;
|
window.localStorage = chrome.storage.local;
|
||||||
|
|
@ -57,12 +56,8 @@ LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||||
|
|
||||||
LocalStorage.prototype.setItem = function(k, v, cb) {
|
LocalStorage.prototype.setItem = function(k, v, cb) {
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
console.log('.............key', k);
|
|
||||||
console.log('.............value', v);
|
|
||||||
|
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj[k] = v;
|
obj[k] = v;
|
||||||
|
|
||||||
chrome.storage.local.set(obj, cb);
|
chrome.storage.local.set(obj, cb);
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem(k, v);
|
localStorage.setItem(k, v);
|
||||||
|
|
|
||||||
18
js/routes.js
18
js/routes.js
|
|
@ -1,5 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var LS = require('../plugins/LocalStorage');
|
||||||
|
var ls = new LS();
|
||||||
|
|
||||||
//Setting up route
|
//Setting up route
|
||||||
angular
|
angular
|
||||||
.module('copayApp')
|
.module('copayApp')
|
||||||
|
|
@ -120,20 +123,7 @@ angular
|
||||||
$rootScope.$on('$routeChangeStart', function(event, next, current) {
|
$rootScope.$on('$routeChangeStart', function(event, next, current) {
|
||||||
|
|
||||||
|
|
||||||
var localStorage;
|
if (!ls || ls.length < 1) {
|
||||||
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
|
||||||
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('localStorage', localStorage);
|
|
||||||
} else {
|
|
||||||
console.log('Is web!');
|
|
||||||
localStorage = window.localStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!localStorage || localStorage.length < 1) {
|
|
||||||
$location.path('unsupported');
|
$location.path('unsupported');
|
||||||
} else {
|
} else {
|
||||||
if (!$rootScope.iden && next.logged) {
|
if (!$rootScope.iden && next.logged) {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,26 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('applicationService', function() {
|
.factory('applicationService', function() {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
|
||||||
|
|
||||||
root.restart = function() {
|
root.restart = function() {
|
||||||
// Go home reloading the application
|
|
||||||
var hashIndex = window.location.href.indexOf('#!/');
|
console.log('RESTART');
|
||||||
|
|
||||||
|
// Go home reloading the application
|
||||||
|
var hashIndex = window.location.href.indexOf('#!/');
|
||||||
|
if (isChromeApp) {
|
||||||
|
console.log('isChromeApp restting ');
|
||||||
|
chrome.runtime.restart();
|
||||||
|
} else {
|
||||||
window.location = window.location.href.substr(0, hashIndex);
|
window.location = window.location.href.substr(0, hashIndex);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
root.reload = function() {
|
root.reload = function() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var LS = require('../plugins/LocalStorage');
|
||||||
|
var ls = new LS();
|
||||||
|
|
||||||
angular.module('copayApp.services').
|
angular.module('copayApp.services').
|
||||||
factory('notification', ['$timeout',
|
factory('notification', ['$timeout',
|
||||||
function($timeout) {
|
function($timeout) {
|
||||||
|
|
||||||
var localStorage;
|
|
||||||
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
|
||||||
console.log('Is a chrome app!...notification.js');
|
|
||||||
localStorage = chrome.storage.local;
|
|
||||||
} else {
|
|
||||||
console.log('Is web!');
|
|
||||||
localStorage = window.localStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
var notifications = [];
|
var notifications = [];
|
||||||
|
|
||||||
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
ls.getItem('notifications', function(err, data) {
|
||||||
localStorage.get('notifications', function(data) {
|
if (data) {
|
||||||
console.log('data', data);
|
notifications = JSON.parse(data);
|
||||||
if (data) {
|
}
|
||||||
notifications = JSON.parse(data);
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
notifications = JSON.parse(localStorage.getItem('notifications')) || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var queue = [];
|
var queue = [];
|
||||||
var settings = {
|
var settings = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue