Solving chrome app problems
This commit is contained in:
parent
bbd00cf2d6
commit
40910c3b34
11 changed files with 204 additions and 45 deletions
|
|
@ -4,7 +4,8 @@
|
||||||
"description": "A multisignature bitcoin wallet",
|
"description": "A multisignature bitcoin wallet",
|
||||||
"version": "APP_VERSION",
|
"version": "APP_VERSION",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage", "notifications"
|
"storage",
|
||||||
|
"notifications"
|
||||||
],
|
],
|
||||||
"app": {
|
"app": {
|
||||||
"background": {
|
"background": {
|
||||||
|
|
|
||||||
11
init.js
11
init.js
|
|
@ -1,7 +1,12 @@
|
||||||
var ld = (document.all);
|
var isChromeApp = window.chrome && chrome.runtime && chrome.runtime.id;
|
||||||
|
var ld;
|
||||||
|
if (!isChromeApp) {
|
||||||
|
ld = (document.all);
|
||||||
|
}
|
||||||
|
|
||||||
var ns4 = document.layers;
|
var ns4 = document.layers;
|
||||||
var ns6 = document.getElementById && !document.all;
|
var ns6 = !isChromeApp && document.getElementById && !document.all;
|
||||||
var ie4 = document.all;
|
var ie4 = !isChromeApp && document.all;
|
||||||
if (ns4) {
|
if (ns4) {
|
||||||
ld = document.loading;
|
ld = document.loading;
|
||||||
} else if (ns6) {
|
} else if (ns6) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
chrome.app.runtime.onLaunched.addListener(function() {
|
chrome.app.runtime.onLaunched.addListener(function() {
|
||||||
chrome.app.window.create('index.html', {
|
chrome.app.window.create('index.html', {
|
||||||
'bounds': {
|
'bounds': {
|
||||||
'width': 1280,
|
'width': 1024,
|
||||||
'height': 800
|
'height': 768
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
23
js/app.js
23
js/app.js
|
|
@ -3,7 +3,23 @@
|
||||||
var copay = require('copay');
|
var copay = require('copay');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var config = defaultConfig;
|
var config = defaultConfig;
|
||||||
var localConfig = JSON.parse(localStorage.getItem('config'));
|
|
||||||
|
var localStorage;
|
||||||
|
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
||||||
|
console.log('Is a chrome app!');
|
||||||
|
localStorage = chrome.storage.local;
|
||||||
|
console.log('localStorage', localStorage);
|
||||||
|
} else {
|
||||||
|
console.log('Is web!');
|
||||||
|
localStorage = window.localStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
var localConfig;
|
||||||
|
if (localStorage) {
|
||||||
|
localConfig = JSON.parse(localStorage.getItem('config'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var defaults = JSON.parse(JSON.stringify(defaultConfig));
|
var defaults = JSON.parse(JSON.stringify(defaultConfig));
|
||||||
|
|
||||||
if (localConfig) {
|
if (localConfig) {
|
||||||
|
|
@ -47,9 +63,10 @@ copayApp.config(function($sceDelegateProvider) {
|
||||||
});
|
});
|
||||||
|
|
||||||
angular.module('ui.gravatar').config([
|
angular.module('ui.gravatar').config([
|
||||||
'gravatarServiceProvider', function(gravatarServiceProvider) {
|
'gravatarServiceProvider',
|
||||||
|
function(gravatarServiceProvider) {
|
||||||
gravatarServiceProvider.defaults = {
|
gravatarServiceProvider.defaults = {
|
||||||
size : 35
|
size: 35
|
||||||
};
|
};
|
||||||
// Use https endpoint
|
// Use https endpoint
|
||||||
gravatarServiceProvider.secure = true;
|
gravatarServiceProvider.secure = true;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
@ -30,14 +32,16 @@ angular.module('copayApp.controllers').controller('HeadController', function($sc
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ensures a graceful disconnect
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
$scope.signout();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.$on('$destroy', function() {
|
//mpando restore after solve some chrome app error
|
||||||
window.onbeforeunload = undefined;
|
// Ensures a graceful disconnect
|
||||||
});
|
// window.onbeforeunload = function() {
|
||||||
|
// $scope.signout();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// $scope.$on('$destroy', function() {
|
||||||
|
// window.onbeforeunload = undefined;
|
||||||
|
// });
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
if (!$rootScope.wallet) return;
|
if (!$rootScope.wallet) return;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,18 @@ 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!');
|
||||||
|
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 = [];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('UnsupportedController',
|
angular.module('copayApp.controllers').controller('UnsupportedController',
|
||||||
function($scope, $location) {
|
function($scope, $location) {
|
||||||
|
|
||||||
|
var localStorage;
|
||||||
|
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
||||||
|
console.log('Is a chrome app!');
|
||||||
|
localStorage = chrome.storage.local;
|
||||||
|
} else {
|
||||||
|
console.log('Is web!');
|
||||||
|
localStorage = window.localStorage;
|
||||||
|
}
|
||||||
if (localStorage && localStorage.length > 0) {
|
if (localStorage && localStorage.length > 0) {
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,133 @@
|
||||||
'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;
|
||||||
|
|
||||||
function LocalStorage(opts) {
|
|
||||||
|
function LocalStorage() {
|
||||||
this.type = 'DB';
|
this.type = 'DB';
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
|
|
||||||
this.ls = opts.ls
|
if (isChromeApp) {
|
||||||
|| ( (typeof localStorage !== 'undefined') ? localStorage : null );
|
localStorage = chrome.storage.local;
|
||||||
|
window.localStorage = chrome.storage.local;
|
||||||
|
}
|
||||||
|
|
||||||
preconditions.checkState(this.ls,
|
preconditions.checkState(typeof localStorage !== 'undefined',
|
||||||
'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) {
|
||||||
// NOP
|
this.email = email;
|
||||||
|
this.password = password;
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.getItem = function(k,cb) {
|
LocalStorage.prototype.getItem = function(k, cb) {
|
||||||
preconditions.checkArgument(_.isFunction(cb));
|
if (isChromeApp) {
|
||||||
return cb(null, this.ls.getItem(k));
|
chrome.storage.local.get(k,
|
||||||
|
function(data) {
|
||||||
|
//TODO check for errors
|
||||||
|
return cb(null, data[k]);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return cb(null, localStorage.getItem(k));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as setItem, but fails if an item already exists
|
* Same as setItem, but fails if an item already exists
|
||||||
*/
|
*/
|
||||||
LocalStorage.prototype.createItem = function(name, value, callback) {
|
LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||||
preconditions.checkArgument(_.isFunction(callback));
|
var self = this;
|
||||||
if (this.ls.getItem(name)) {
|
console.log('createItem ');
|
||||||
return callback('EEXISTS');
|
self.getItem(name,
|
||||||
|
function(err, data) {
|
||||||
|
console.log('error ', err);
|
||||||
|
console.log('data ', data);
|
||||||
|
if (data) {
|
||||||
|
return callback('EEXISTS');
|
||||||
|
} else {
|
||||||
|
console.log('calling setitem ');
|
||||||
|
return self.setItem(name, value, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalStorage.prototype.setItem = function(k, v, cb) {
|
||||||
|
if (isChromeApp) {
|
||||||
|
console.log('.............key', k);
|
||||||
|
console.log('.............value', v);
|
||||||
|
|
||||||
|
var obj = {};
|
||||||
|
obj[k] = v;
|
||||||
|
|
||||||
|
chrome.storage.local.set(obj, cb);
|
||||||
|
} else {
|
||||||
|
localStorage.setItem(k, v);
|
||||||
|
return cb();
|
||||||
}
|
}
|
||||||
return this.setItem(name, value, callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.setItem = function(k,v,cb) {
|
LocalStorage.prototype.removeItem = function(k, cb) {
|
||||||
preconditions.checkArgument(_.isFunction(cb));
|
if (isChromeApp) {
|
||||||
this.ls.setItem(k,v);
|
chrome.storage.remove(k, cb);
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem(k);
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalStorage.prototype.clear = function(cb) {
|
||||||
|
if (isChromeApp) {
|
||||||
|
chrome.storage.clear();
|
||||||
|
} else {
|
||||||
|
localStorage.clear();
|
||||||
|
}
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.removeItem = function(k,cb) {
|
LocalStorage.prototype.allKeys = function(cb) {
|
||||||
preconditions.checkArgument(_.isFunction(cb));
|
|
||||||
this.ls.removeItem(k);
|
if (isChromeApp) {
|
||||||
return cb();
|
chrome.storage.local.get(null, function(items) {
|
||||||
|
return cb(null, _.keys(items));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var ret = [];
|
||||||
|
var l = localStorage.length;
|
||||||
|
|
||||||
|
for (var i = 0; i < l; i++)
|
||||||
|
ret.push(localStorage.key(i));
|
||||||
|
|
||||||
|
return cb(null, ret);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.clear = function(cb) {
|
LocalStorage.prototype.getFirst = function(prefix, opts, cb) {
|
||||||
preconditions.checkArgument(_.isFunction(cb));
|
opts = opts || {};
|
||||||
this.ls.clear();
|
var that = this;
|
||||||
return cb();
|
|
||||||
|
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;
|
||||||
|
|
|
||||||
13
js/routes.js
13
js/routes.js
|
|
@ -118,6 +118,19 @@ angular
|
||||||
uriHandler.register();
|
uriHandler.register();
|
||||||
}
|
}
|
||||||
$rootScope.$on('$routeChangeStart', function(event, next, current) {
|
$rootScope.$on('$routeChangeStart', function(event, next, current) {
|
||||||
|
|
||||||
|
var localStorage;
|
||||||
|
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
||||||
|
console.log('Is a chrome app!');
|
||||||
|
localStorage = chrome.storage.local;
|
||||||
|
|
||||||
|
console.log('chrome.storage', chrome.storage);
|
||||||
|
console.log('localStorage', localStorage);
|
||||||
|
} else {
|
||||||
|
console.log('Is web!');
|
||||||
|
localStorage = window.localStorage;
|
||||||
|
}
|
||||||
|
|
||||||
if (!localStorage || localStorage.length < 1) {
|
if (!localStorage || localStorage.length < 1) {
|
||||||
$location.path('unsupported');
|
$location.path('unsupported');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,31 @@ angular.module('copayApp.services').
|
||||||
factory('notification', ['$timeout',
|
factory('notification', ['$timeout',
|
||||||
function($timeout) {
|
function($timeout) {
|
||||||
|
|
||||||
var notifications = JSON.parse(localStorage.getItem('notifications')) || [],
|
var localStorage;
|
||||||
queue = [];
|
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
||||||
|
console.log('Is a chrome app!');
|
||||||
|
localStorage = chrome.storage.local;
|
||||||
|
} else {
|
||||||
|
console.log('Is web!');
|
||||||
|
localStorage = window.localStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
var notifications = [];
|
||||||
|
|
||||||
|
if (window.chrome && chrome.runtime && chrome.runtime.id) {
|
||||||
|
localStorage.get('notifications', function(data) {
|
||||||
|
console.log('data', data);
|
||||||
|
if (data) {
|
||||||
|
notifications = JSON.parse(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
notifications = JSON.parse(localStorage.getItem('notifications')) || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var queue = [];
|
||||||
var settings = {
|
var settings = {
|
||||||
info: {
|
info: {
|
||||||
duration: 6000,
|
duration: 6000,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ var ls;
|
||||||
try {
|
try {
|
||||||
var LS = require('../js/plugins/LocalStorage');
|
var LS = require('../js/plugins/LocalStorage');
|
||||||
ls = new LS();
|
ls = new LS();
|
||||||
} catch(e) {};
|
} catch (e) {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc
|
* @desc
|
||||||
|
|
@ -126,6 +126,7 @@ var error = new Error();
|
||||||
|
|
||||||
var logLevel = config.logLevel || 'info';
|
var logLevel = config.logLevel || 'info';
|
||||||
|
|
||||||
|
|
||||||
if (ls && ls.getItem) {
|
if (ls && ls.getItem) {
|
||||||
ls.getItem("config", function(err, value) {
|
ls.getItem("config", function(err, value) {
|
||||||
if (err) return;
|
if (err) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue