Chrome App fixes
This commit is contained in:
parent
5bfbf64778
commit
5b0e5f51db
7 changed files with 24 additions and 49 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
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 LS = require('../js/plugins/LocalStorage');
|
||||||
var ls = new LS();
|
var ls = new LS();
|
||||||
|
|
||||||
var localConfig;
|
var localConfig;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ angular.module('copayApp.controllers').controller('HeadController', function($sc
|
||||||
$scope.username = $rootScope.iden.getName();
|
$scope.username = $rootScope.iden.getName();
|
||||||
$scope.hoverMenu = false;
|
$scope.hoverMenu = false;
|
||||||
|
|
||||||
console.log('$scope.username', $scope.username);
|
|
||||||
|
|
||||||
$scope.hoverIn = function() {
|
$scope.hoverIn = function() {
|
||||||
this.hoverMenu = true;
|
this.hoverMenu = true;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,8 @@ angular.module('copayApp.controllers').controller('UnsupportedController',
|
||||||
|
|
||||||
var localStorage;
|
var localStorage;
|
||||||
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
||||||
console.log('Is a chrome app!..unssoported.js');
|
|
||||||
localStorage = chrome.storage.local;
|
localStorage = chrome.storage.local;
|
||||||
} else {
|
} else {
|
||||||
console.log('Is web!');
|
|
||||||
localStorage = window.localStorage;
|
localStorage = window.localStorage;
|
||||||
}
|
}
|
||||||
if (localStorage && localStorage.length > 0) {
|
if (localStorage && localStorage.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,32 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var preconditions = require('preconditions').singleton();
|
var preconditions = require('preconditions').singleton();
|
||||||
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
|
var isChromeApp = typeof window !== "undefined" && window.chrome && chrome.runtime && chrome.runtime.id;
|
||||||
|
|
||||||
|
|
||||||
function LocalStorage() {
|
function LocalStorage(opts) {
|
||||||
this.type = 'DB';
|
this.type = 'DB';
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
if (isChromeApp) {
|
|
||||||
localStorage = chrome.storage.local;
|
|
||||||
|
|
||||||
|
this.ls = opts.ls ||
|
||||||
|
((typeof localStorage !== "undefined") ? localStorage : null);
|
||||||
|
|
||||||
|
if (isChromeApp && !this.ls) {
|
||||||
|
this.ls = localStorage = chrome.storage.local;
|
||||||
window.localStorage = chrome.storage.local;
|
window.localStorage = chrome.storage.local;
|
||||||
}
|
}
|
||||||
|
|
||||||
preconditions.checkState(typeof localStorage !== 'undefined',
|
preconditions.checkState(this.ls,
|
||||||
'localstorage not available, cannot run plugin');
|
'localstorage not available, cannot run plugin');
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.init = function() {};
|
LocalStorage.prototype.init = function() {};
|
||||||
|
|
||||||
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
||||||
this.email = email;
|
// NOP
|
||||||
this.password = password;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.getItem = function(k, cb) {
|
LocalStorage.prototype.getItem = function(k, cb) {
|
||||||
|
|
@ -31,7 +37,7 @@ LocalStorage.prototype.getItem = function(k, cb) {
|
||||||
return cb(null, data[k]);
|
return cb(null, data[k]);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return cb(null, localStorage.getItem(k));
|
return cb(null, this.ls.getItem(k));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -40,15 +46,11 @@ LocalStorage.prototype.getItem = function(k, cb) {
|
||||||
*/
|
*/
|
||||||
LocalStorage.prototype.createItem = function(name, value, callback) {
|
LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
console.log('createItem ');
|
|
||||||
self.getItem(name,
|
self.getItem(name,
|
||||||
function(err, data) {
|
function(err, data) {
|
||||||
console.log('error ', err);
|
|
||||||
console.log('data ', data);
|
|
||||||
if (data) {
|
if (data) {
|
||||||
return callback('EEXISTS');
|
return callback('EEXISTS');
|
||||||
} else {
|
} else {
|
||||||
console.log('calling setitem ');
|
|
||||||
return self.setItem(name, value, callback);
|
return self.setItem(name, value, callback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -58,9 +60,10 @@ LocalStorage.prototype.setItem = function(k, v, cb) {
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
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);
|
this.ls.setItem(k, v);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,7 +73,7 @@ LocalStorage.prototype.removeItem = function(k, cb) {
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
chrome.storage.remove(k, cb);
|
chrome.storage.remove(k, cb);
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(k);
|
this.ls.removeItem(k);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,50 +83,27 @@ LocalStorage.prototype.clear = function(cb) {
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
chrome.storage.clear();
|
chrome.storage.clear();
|
||||||
} else {
|
} else {
|
||||||
localStorage.clear();
|
this.ls.clear();
|
||||||
}
|
}
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.allKeys = function(cb) {
|
LocalStorage.prototype.allKeys = function(cb) {
|
||||||
|
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
chrome.storage.local.get(null, function(items) {
|
chrome.storage.local.get(null, function(items) {
|
||||||
return cb(null, _.keys(items));
|
return cb(null, _.keys(items));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
var l = localStorage.length;
|
var l = this.ls.length;
|
||||||
|
|
||||||
for (var i = 0; i < l; i++)
|
for (var i = 0; i < l; i++)
|
||||||
ret.push(localStorage.key(i));
|
ret.push(this.ls.key(i));
|
||||||
|
|
||||||
return cb(null, ret);
|
return cb(null, ret);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.getFirst = function(prefix, opts, cb) {
|
|
||||||
opts = opts || {};
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
this.allKeys(function(err, allKeys) {
|
|
||||||
var keys = _.filter(allKeys, function(k) {
|
|
||||||
if ((k === prefix) || k.indexOf(prefix) === 0) return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (keys.length === 0)
|
|
||||||
return cb(new Error('not found'));
|
|
||||||
|
|
||||||
if (opts.onlyKey)
|
|
||||||
return cb(null, null, keys[0]);
|
|
||||||
|
|
||||||
that.getItem(keys[0], function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
return cb(null, data, keys[0]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = LocalStorage;
|
module.exports = LocalStorage;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var LS = require('../plugins/LocalStorage');
|
var LS = require('../js/plugins/LocalStorage');
|
||||||
var ls = new LS();
|
var ls = new LS();
|
||||||
|
|
||||||
//Setting up route
|
//Setting up route
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@ angular.module('copayApp.services')
|
||||||
// Go home reloading the application
|
// Go home reloading the application
|
||||||
var hashIndex = window.location.href.indexOf('#!/');
|
var hashIndex = window.location.href.indexOf('#!/');
|
||||||
if (isChromeApp) {
|
if (isChromeApp) {
|
||||||
console.log('isChromeApp restting ');
|
chrome.runtime.reload();
|
||||||
chrome.runtime.restart();
|
|
||||||
} else {
|
} else {
|
||||||
window.location = window.location.href.substr(0, hashIndex);
|
window.location = window.location.href.substr(0, hashIndex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var LS = require('../plugins/LocalStorage');
|
var LS = require('../js/plugins/LocalStorage');
|
||||||
var ls = new LS();
|
var ls = new LS();
|
||||||
|
|
||||||
angular.module('copayApp.services').
|
angular.module('copayApp.services').
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue