Merge pull request #2644 from matiu/bug/android-file

write file not as blobs
This commit is contained in:
Matias Alejo Garcia 2015-04-27 15:35:54 -03:00
commit 0479ef0f34
2 changed files with 79 additions and 78 deletions

View file

@ -246,13 +246,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}; };
self.handleError = function(err) { self.handleError = function(err) {
$log.debug('ERROR:', err); $log.warn('Client ERROR:', err);
if (err.code === 'NOTAUTHORIZED') { if (err.code === 'NOTAUTHORIZED') {
$scope.$emit('Local/NotAuthorized'); $scope.$emit('Local/NotAuthorized');
} else if (err.code === 'NOTFOUND') { } else if (err.code === 'NOTFOUND') {
$scope.$emit('Local/BWSNotFound'); $scope.$emit('Local/BWSNotFound');
} else { } else {
$scope.$emit('Local/ClientError', err); $scope.$emit('Local/ClientError', (err.error ? err.error : err));
} }
}; };
self.openWallet = function() { self.openWallet = function() {
@ -448,7 +448,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setOngoingProcess('recreating', false); self.setOngoingProcess('recreating', false);
if (err) { if (err) {
self.clientError('Could not recreate wallet:' + err); self.handleError(err);
$rootScope.$apply(); $rootScope.$apply();
return; return;
} }
@ -485,7 +485,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (err) { if (err) {
if (self.walletId == walletId) if (self.walletId == walletId)
self.setOngoingProcess('scanning', false); self.setOngoingProcess('scanning', false);
self.clientError('Could not scan wallet:' + err); self.handleError(err);
$rootScope.$apply(); $rootScope.$apply();
} }
}); });
@ -533,6 +533,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// UX event handlers // UX event handlers
$rootScope.$on('Local/ColorUpdated', function(event) { $rootScope.$on('Local/ColorUpdated', function(event) {
self.updateColor(); self.updateColor();
$timeout(function() {
$rootScope.$apply();
});
}); });
$rootScope.$on('Local/UnitSettingUpdated', function(event) { $rootScope.$on('Local/UnitSettingUpdated', function(event) {
@ -569,7 +572,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/BackupDone', function(event) { $rootScope.$on('Local/BackupDone', function(event) {
self.needsBackup = false; self.needsBackup = false;
storageService.setBackupFlag(self.walletId, function() {}); storageService.setBackupFlag(self.walletId, function(err) {
if (err) $rootScope.$emit('Local/DeviceError', err)
});
}); });
$rootScope.$on('Local/NotAuthorized', function(event) { $rootScope.$on('Local/NotAuthorized', function(event) {

View file

@ -3,16 +3,20 @@
angular.module('copayApp.services') angular.module('copayApp.services')
.factory('fileStorageService', function(lodash, $log) { .factory('fileStorageService', function(lodash, $log) {
var root = {}, var root = {},
fs; _fs, _dir;
root.init = function(cb) { root.init = function(cb) {
if (fs) return cb(null, fs); if (_dir) return cb(null, _fs, _dir);
function onFileSystemSuccess(fileSystem) { function onFileSystemSuccess(fileSystem) {
console.log('File system started: ', fileSystem.name, fileSystem.root.name); console.log('File system started: ', fileSystem.name, fileSystem.root.name);
fs = fileSystem; _fs = fileSystem;
return cb(null, fs); root.getDir(function(err, newDir) {
if (err || !newDir.nativeURL) return cb(err);
_dir = newDir
$log.debug("Got main dir:", _dir.nativeURL);
return cb(null, _fs, _dir);
});
} }
function fail(evt) { function fail(evt) {
@ -24,13 +28,9 @@ angular.module('copayApp.services')
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
}; };
root.get = function(k, cb) { root.get = function(k, cb) {
root.init(function(err, fs) { root.init(function(err, fs, dir) {
if (err) return cb(err); if (err) return cb(err);
root.getDir(function(err, dir) {
if (err) return cb(err);
$log.debug(".get: Got main dir:", dir.nativeURL);
dir.getFile(k, { dir.getFile(k, {
create: false, create: false,
}, function(fileEntry) { }, function(fileEntry) {
@ -51,16 +51,12 @@ angular.module('copayApp.services')
if (err.code == 1) return cb(); if (err.code == 1) return cb();
else return cb(err); else return cb(err);
}); });
});
}) })
}; };
root.set = function(k, v, cb) { root.set = function(k, v, cb) {
root.init(function(err, fs) { root.init(function(err, fs, dir) {
if (err) return cb(err); if (err) return cb(err);
root.getDir(function(err, dir) {
if (err) return cb(err);
$log.debug(".set: Got main dir:", dir.nativeURL);
dir.getFile(k, { dir.getFile(k, {
create: true, create: true,
}, function(fileEntry) { }, function(fileEntry) {
@ -73,23 +69,24 @@ angular.module('copayApp.services')
}; };
fileWriter.onerror = function(e) { fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString()); var err = e.error ? e.error : JSON.stringify(e);
return cb('Fail to write:', e.toString()); console.log('Write failed: ' + err);
return cb('Fail to write:' + err);
}; };
if (lodash.isObject(v)) if (lodash.isObject(v))
v = JSON.stringify(v); v = JSON.stringify(v);
if (!lodash.isString(v)){
v = v.toString();
}
$log.debug('Writing:', k, v); $log.debug('Writing:', k, v);
var blob = new Blob([v], { fileWriter.write(v);
type: "text/plain"
});
fileWriter.write(blob);
}, cb); }, cb);
}); });
}); });
});
}; };
@ -105,13 +102,14 @@ angular.module('copayApp.services')
// url = 'ms-appdata:///local/'; // url = 'ms-appdata:///local/';
window.resolveLocalFileSystemURL(url, function(dir) { window.resolveLocalFileSystemURL(url, function(dir) {
return cb(null, dir); return cb(null, dir);
}, function(err) {
$log.warn(err);
return cb(err || 'Could not resolve filesystem:' + url);
}); });
}; };
root.remove = function(k, cb) { root.remove = function(k, cb) {
root.init(function(err, fs) { root.init(function(err, fs, dir) {
if (err) return cb(err);
root.getDir(function(err, dir) {
if (err) return cb(err); if (err) return cb(err);
dir.getFile(k, { dir.getFile(k, {
create: false, create: false,
@ -123,7 +121,6 @@ angular.module('copayApp.services')
}, cb, cb); }, cb, cb);
}); });
}); });
});
}; };
/** /**
@ -140,6 +137,5 @@ angular.module('copayApp.services')
}); });
}; };
return root; return root;
}); });