mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -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);
|
var file = 'whiteout_mail_' + userId + '_' + keyId.substring(8, keyId.length);
|
||||||
|
|
||||||
dl.createDownload({
|
dl.createDownload({
|
||||||
content: keys.publicKey.publicKey + keys.privateKey.encryptedKey,
|
content: keys.publicKey.publicKey + '\r\n' + keys.privateKey.encryptedKey,
|
||||||
filename: file + '.asc',
|
filename: file + '.asc',
|
||||||
contentType: 'text/plain'
|
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;
|
return AccountCtrl;
|
||||||
|
@ -67,7 +67,7 @@ define(function(require) {
|
|||||||
function checkPublicKey(user) {
|
function checkPublicKey(user) {
|
||||||
user.secure = undefined;
|
user.secure = undefined;
|
||||||
|
|
||||||
if(!keychain) {
|
if (!keychain) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ define(function(require) {
|
|||||||
content: attachment.content,
|
content: attachment.content,
|
||||||
filename: attachment.filename,
|
filename: attachment.filename,
|
||||||
contentType: attachment.mimeType
|
contentType: attachment.mimeType
|
||||||
}, $scope.onError);
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ define(function(require) {
|
|||||||
var iframe = elm[0];
|
var iframe = elm[0];
|
||||||
|
|
||||||
scope.$watch('state.read.open', function(open) {
|
scope.$watch('state.read.open', function(open) {
|
||||||
if(open) {
|
if (open) {
|
||||||
// trigger rendering of iframe
|
// trigger rendering of iframe
|
||||||
// otherwise scale to fit would not compute correct dimensions on mobile
|
// otherwise scale to fit would not compute correct dimensions on mobile
|
||||||
displayText(scope.state.mailList.selected ? scope.state.mailList.selected.body : undefined);
|
displayText(scope.state.mailList.selected ? scope.state.mailList.selected.body : undefined);
|
||||||
@ -267,7 +267,7 @@ define(function(require) {
|
|||||||
var w = elm.width();
|
var w = elm.width();
|
||||||
var scale = '';
|
var scale = '';
|
||||||
|
|
||||||
if(w > parentWidth) {
|
if (w > parentWidth) {
|
||||||
scale = parentWidth / w;
|
scale = parentWidth / w;
|
||||||
scale = 'scale(' + scale + ',' + scale + ')';
|
scale = 'scale(' + scale + ',' + scale + ')';
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ define(function(require) {
|
|||||||
|
|
||||||
var dl = {};
|
var dl = {};
|
||||||
|
|
||||||
dl.createDownload = function(options, callback) {
|
dl.createDownload = function(options) {
|
||||||
var contentType = options.contentType || 'application/octet-stream';
|
var contentType = options.contentType || 'application/octet-stream';
|
||||||
var filename = options.filename || 'file';
|
var filename = options.filename || 'file';
|
||||||
var content = options.content;
|
var content = options.content;
|
||||||
@ -16,28 +16,7 @@ define(function(require) {
|
|||||||
supportsBlob = !!new Blob();
|
supportsBlob = !!new Blob();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
if (window.chrome && window.chrome.fileSystem) {
|
if (typeof a.download !== "undefined" && supportsBlob) {
|
||||||
// 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) {
|
|
||||||
// ff 30+, chrome 27+ (android: 37+)
|
// ff 30+, chrome 27+ (android: 37+)
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.style = "display: none";
|
a.style = "display: none";
|
||||||
|
@ -11,9 +11,7 @@
|
|||||||
"196": "img/icon-196.png"
|
"196": "img/icon-196.png"
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"unlimitedStorage", {
|
"unlimitedStorage",
|
||||||
"fileSystem": ["write"]
|
|
||||||
},
|
|
||||||
"notifications",
|
"notifications",
|
||||||
"https://keys-test.whiteout.io/",
|
"https://keys-test.whiteout.io/",
|
||||||
"https://keychain-test.whiteout.io/",
|
"https://keychain-test.whiteout.io/",
|
||||||
|
@ -63,7 +63,7 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('export to key file', function() {
|
describe('export to key file', function() {
|
||||||
it('should work', function(done) {
|
it('should work', function() {
|
||||||
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
var createDownloadMock = sinon.stub(dl, 'createDownload');
|
||||||
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
keychainMock.getUserKeyPair.withArgs(emailAddress).yields(null, {
|
||||||
publicKey: {
|
publicKey: {
|
||||||
@ -75,18 +75,15 @@ define(function(require) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
createDownloadMock.withArgs(sinon.match(function(arg) {
|
createDownloadMock.withArgs(sinon.match(function(arg) {
|
||||||
return arg.content === 'ab' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
return arg.content === 'a\r\nb' && arg.filename === 'whiteout_mail_' + emailAddress + '_' + expectedKeyId + '.asc' && arg.contentType === 'text/plain';
|
||||||
})).yields();
|
})).returns();
|
||||||
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();
|
|
||||||
};
|
|
||||||
|
|
||||||
scope.exportKeyFile();
|
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) {
|
it('should not work when key export failed', function(done) {
|
||||||
@ -99,29 +96,6 @@ define(function(require) {
|
|||||||
|
|
||||||
scope.exportKeyFile();
|
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