From 7f6b41e11d5e09598c11dd550289fae8dad17140 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 26 Apr 2015 11:41:25 -0300 Subject: [PATCH] no file storage from WP --- src/js/controllers/index.js | 1 + src/js/controllers/preferencesLogs.js | 4 ++-- src/js/routes.js | 3 --- src/js/services/fileStorage.js | 25 ++++++++++++++++++++++--- src/js/services/isChromeApp.js | 2 +- src/js/services/logHeader.js | 9 +++++++++ src/js/services/profileService.js | 2 +- src/js/services/storageService.js | 13 ++++++++++--- 8 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/js/services/logHeader.js diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 648a0b10b..6acefe57d 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1,6 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, gettextCatalog, amMoment) { + var self = this; self.isCordova = isCordova; self.onGoingProcess = {}; diff --git a/src/js/controllers/preferencesLogs.js b/src/js/controllers/preferencesLogs.js index 15ff13159..8444c3ae0 100644 --- a/src/js/controllers/preferencesLogs.js +++ b/src/js/controllers/preferencesLogs.js @@ -6,8 +6,8 @@ function(historicLog, isCordova) { this.isCordova = isCordova; this.sendLogs = function() { - var body = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n Copay v' + window.version + ' #' + window.commitHash; - body += '\n\n' + var body = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n'; + body += '\n\n'; body += this.logs.map(function(v) { return v.msg; }).join('\n'); diff --git a/src/js/routes.js b/src/js/routes.js index 4fd6fc8da..5bfa59519 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -447,11 +447,8 @@ angular }); }) .run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService) { - - $log.debug('Attaching FastClick'); FastClick.attach(document.body); - // Auto-detect browser language var userLang, androidLang; diff --git a/src/js/services/fileStorage.js b/src/js/services/fileStorage.js index a8b09c54d..2a14db7a5 100644 --- a/src/js/services/fileStorage.js +++ b/src/js/services/fileStorage.js @@ -28,7 +28,8 @@ angular.module('copayApp.services') root.get = function(k, cb) { root.init(function(err, fs) { if (err) return cb(err); - window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + root.getDir(function(err, dir) { + if (err) return cb(err); $log.debug(".get: Got main dir:", dir.nativeURL); dir.getFile(k, { create: false, @@ -57,7 +58,8 @@ angular.module('copayApp.services') root.set = function(k, v, cb) { root.init(function(err, fs) { if (err) return cb(err); - window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + root.getDir(function(err, dir) { + if (err) return cb(err); $log.debug(".set: Got main dir:", dir.nativeURL); dir.getFile(k, { create: true, @@ -90,10 +92,27 @@ angular.module('copayApp.services') }); }; + + // See https://github.com/apache/cordova-plugin-file/#where-to-store-files + root.getDir = function(cb) { + if (!cordova.file) { + return cb('Could not write on device storage'); + } + + var url = cordova.file.dataDirectory; + // This could be needed for windows + // if (cordova.file === undefined) { + // url = 'ms-appdata:///local/'; + window.resolveLocalFileSystemURL(url, function(dir) { + return cb(null, dir); + }); + }; + root.remove = function(k, cb) { root.init(function(err, fs) { if (err) return cb(err); - window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) { + root.getDir(function(err, dir) { + if (err) return cb(err); dir.getFile(k, { create: false, }, function(fileEntry) { diff --git a/src/js/services/isChromeApp.js b/src/js/services/isChromeApp.js index 22c0c13b8..72a8e275e 100644 --- a/src/js/services/isChromeApp.js +++ b/src/js/services/isChromeApp.js @@ -1,4 +1,4 @@ 'use strict'; -angular.module('copayApp.services').value('isChromeApp', window.chrome && chrome.runtime && chrome.runtime.id); +angular.module('copayApp.services').value('isChromeApp', !!(window.chrome && chrome.runtime && chrome.runtime.id)); diff --git a/src/js/services/logHeader.js b/src/js/services/logHeader.js new file mode 100644 index 000000000..ef64fb45b --- /dev/null +++ b/src/js/services/logHeader.js @@ -0,0 +1,9 @@ +'use strict'; +angular.module('copayApp.services') + .factory('logHeader', function($log, isChromeApp, isCordova) { + $log.info('Starting Copay v' + window.version + ' #' + window.commitHash); + $log.info('Client: isCordova:', isCordova, 'isChromeApp:', isChromeApp); + $log.info('Navigator:', navigator.userAgent); + + return {}; + }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 7d488952a..dc9d353ab 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, pluginManager, balanceService, applicationService, storageService, bwcService, configService, notificationService, notification, isChromeApp) { + .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova) { var root = {}; diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 99a7f5fe7..65387942c 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -1,9 +1,16 @@ 'use strict'; angular.module('copayApp.services') - .factory('storageService', function(fileStorageService, localStorageService, sjcl, $log, lodash, isCordova) { + .factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, isCordova) { var root = {}; - var storage = isCordova ? fileStorageService : localStorageService; + + // File storage is not supported for writting according to + // https://github.com/apache/cordova-plugin-file/#supported-platforms + var shouldUseFileStorage = isCordova && !isMobile.Windows(); + $log.debug('Using file storage:', shouldUseFileStorage); + + + var storage = shouldUseFileStorage ? fileStorageService : localStorageService; var getUUID = function(cb) { // TO SIMULATE MOBILE @@ -50,7 +57,7 @@ angular.module('copayApp.services') root.tryToMigrate = function(cb) { - if (!isCordova) return cb(); + if (!shouldUseFileStorage) return cb(); localStorageService.get('profile', function(err, str) { if (err) return cb(err);