mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 18:32:20 -05:00
Remove chrome.filesystem and use only standard apis
This commit is contained in:
parent
53341f02a2
commit
0613016581
@ -49,26 +49,12 @@ define(function(require) {
|
||||
var file = 'whiteout_mail_' + userId + '_' + keyId.substring(8, keyId.length);
|
||||
|
||||
dl.createDownload({
|
||||
content: keys.publicKey.publicKey + keys.privateKey.encryptedKey,
|
||||
content: keys.publicKey.publicKey + '\r\n' + keys.privateKey.encryptedKey,
|
||||
filename: file + '.asc',
|
||||
contentType: 'text/plain'
|
||||
}, onExport);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function onExport(err) {
|
||||
if (err) {
|
||||
$scope.onError(err);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.state.account.toggle(false);
|
||||
$scope.$apply();
|
||||
$scope.onError({
|
||||
title: 'Success',
|
||||
message: 'Exported keypair to file.'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return AccountCtrl;
|
||||
|
@ -67,7 +67,7 @@ define(function(require) {
|
||||
function checkPublicKey(user) {
|
||||
user.secure = undefined;
|
||||
|
||||
if(!keychain) {
|
||||
if (!keychain) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ define(function(require) {
|
||||
content: attachment.content,
|
||||
filename: attachment.filename,
|
||||
contentType: attachment.mimeType
|
||||
}, $scope.onError);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ define(function(require) {
|
||||
var iframe = elm[0];
|
||||
|
||||
scope.$watch('state.read.open', function(open) {
|
||||
if(open) {
|
||||
if (open) {
|
||||
// trigger rendering of iframe
|
||||
// otherwise scale to fit would not compute correct dimensions on mobile
|
||||
displayText(scope.state.mailList.selected ? scope.state.mailList.selected.body : undefined);
|
||||
@ -267,7 +267,7 @@ define(function(require) {
|
||||
var w = elm.width();
|
||||
var scale = '';
|
||||
|
||||
if(w > parentWidth) {
|
||||
if (w > parentWidth) {
|
||||
scale = parentWidth / w;
|
||||
scale = 'scale(' + scale + ',' + scale + ')';
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ define(function(require) {
|
||||
|
||||
var dl = {};
|
||||
|
||||
dl.createDownload = function(options, callback) {
|
||||
dl.createDownload = function(options) {
|
||||
var contentType = options.contentType || 'application/octet-stream';
|
||||
var filename = options.filename || 'file';
|
||||
var content = options.content;
|
||||
@ -16,28 +16,7 @@ define(function(require) {
|
||||
supportsBlob = !!new Blob();
|
||||
} catch (e) {}
|
||||
|
||||
if (window.chrome && window.chrome.fileSystem) {
|
||||
// chrome app
|
||||
chrome.fileSystem.chooseEntry({
|
||||
type: 'saveFile',
|
||||
suggestedName: filename
|
||||
}, function(file) {
|
||||
if (!file) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
file.createWriter(function(writer) {
|
||||
writer.onerror = callback;
|
||||
writer.onwriteend = function() {
|
||||
callback();
|
||||
};
|
||||
writer.write(new Blob([content], {
|
||||
type: contentType
|
||||
}));
|
||||
}, callback);
|
||||
});
|
||||
return;
|
||||
} else if (typeof a.download !== "undefined" && supportsBlob) {
|
||||
if (typeof a.download !== "undefined" && supportsBlob) {
|
||||
// ff 30+, chrome 27+ (android: 37+)
|
||||
document.body.appendChild(a);
|
||||
a.style = "display: none";
|
||||
|
@ -11,9 +11,7 @@
|
||||
"196": "img/icon-196.png"
|
||||
},
|
||||
"permissions": [
|
||||
"unlimitedStorage", {
|
||||
"fileSystem": ["write"]
|
||||
},
|
||||
"unlimitedStorage",
|
||||
"notifications",
|
||||
"https://keys-test.whiteout.io/",
|
||||
"https://keychain-test.whiteout.io/",
|
||||
|
@ -63,7 +63,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
describe('export to key file', function() {
|
||||
it('should work', function(done) {
|
||||
it('should work', function() {
|
||||
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
||||
publicKey: {
|
||||
@ -75,18 +75,15 @@ define(function(require) {
|
||||
}
|
||||
});
|
||||
createDownloadMock.withArgs(sinon.match(function(arg) {
|
||||
return arg.content === 'ab' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
||||
})).yields();
|
||||
scope.onError = function(err) {
|
||||
expect(err.title).to.equal('Success');
|
||||
expect(scope.state.lightbox).to.equal(undefined);
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(dl.createDownload.calledOnce).to.be.true;
|
||||
dl.createDownload.restore();
|
||||
done();
|
||||
};
|
||||
return arg.content === 'a\r\nb' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
||||
})).returns();
|
||||
|
||||
scope.exportKeyFile();
|
||||
|
||||
expect(scope.state.lightbox).to.equal(undefined);
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(dl.createDownload.calledOnce).to.be.true;
|
||||
dl.createDownload.restore();
|
||||
});
|
||||
|
||||
it('should not work when key export failed', function(done) {
|
||||
@ -99,29 +96,6 @@ define(function(require) {
|
||||
|
||||
scope.exportKeyFile();
|
||||
});
|
||||
|
||||
it('should not work when create download failed', function(done) {
|
||||
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
||||
publicKey: {
|
||||
_id: dummyKeyId,
|
||||
publicKey: 'a'
|
||||
},
|
||||
privateKey: {
|
||||
encryptedKey: 'b'
|
||||
}
|
||||
});
|
||||
createDownloadMock.withArgs().yields(new Error('asdasd'));
|
||||
scope.onError = function(err) {
|
||||
expect(err.message).to.equal('asdasd');
|
||||
expect(keychainMock.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(dl.createDownload.calledOnce).to.be.true;
|
||||
dl.createDownload.restore();
|
||||
done();
|
||||
};
|
||||
|
||||
scope.exportKeyFile();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user