1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-30 04:28:19 +02:00

include downloader script and page

This commit is contained in:
Kyle Spearrin 2019-08-21 16:50:15 -04:00
parent 6af618cb41
commit eec577372c
5 changed files with 36 additions and 29 deletions

View File

@ -31,6 +31,9 @@ const filters = {
'!build/safari/**/*', '!build/safari/**/*',
'!build/downloader/**/*' '!build/downloader/**/*'
], ],
safariDir: [
'!build/safari/**/*'
],
webExt: [ webExt: [
'!build/manifest.json' '!build/manifest.json'
], ],
@ -215,7 +218,7 @@ function safariAppCopyBuild(source, dest) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
gulp.src(source) gulp.src(source)
.on('error', reject) .on('error', reject)
.pipe(filter(['**'].concat(filters.edge).concat(filters.fonts).concat(filters.safari) .pipe(filter(['**'].concat(filters.edge).concat(filters.fonts).concat(filters.safariDir)
.concat(filters.webExt).concat(filters.nonSafariApp))) .concat(filters.webExt).concat(filters.nonSafariApp)))
.pipe(gulp.dest(dest)) .pipe(gulp.dest(dest))
.on('end', resolve); .on('end', resolve);

26
src/content/downloader.ts Normal file
View File

@ -0,0 +1,26 @@
document.addEventListener('DOMContentLoaded', (event) => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (!isSafari) {
return;
}
safari.self.addEventListener('message', (msgEvent: any) => {
const msg = JSON.parse(msgEvent.message.msg);
if (msg.command === 'downloaderPageData') {
const blob = new Blob([msg.data.blobData], msg.data.blobOptions);
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, msg.data.fileName);
} else {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = msg.data.fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
window.setTimeout(() => window.close(), 1500);
}
}, false);
});

View File

@ -1,30 +1,3 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && // TODO
navigator.userAgent.indexOf('Chrome') === -1;
if (!isSafari) {
return;
}
safari.self.addEventListener('message', (msgEvent: any) => {
doDownload(JSON.parse(msgEvent.message.msg));
}, false);
function doDownload(msg: any) {
if (msg.command === 'downloaderPageData' && msg.data) {
const blob = new Blob([msg.data.blobData], msg.data.blobOptions);
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, msg.data.fileName);
} else {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = msg.data.fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}
window.setTimeout(() => window.close(), 1500);
}
}); });

View File

@ -53,6 +53,10 @@
<key>Script</key> <key>Script</key>
<string>app/content/shortcuts.js</string> <string>app/content/shortcuts.js</string>
</dict> </dict>
<dict>
<key>Script</key>
<string>app/content/downloader.js</string>
</dict>
</array> </array>
<key>SFSafariToolbarItem</key> <key>SFSafariToolbarItem</key>
<dict> <dict>

View File

@ -145,6 +145,7 @@ const config = {
'background': './src/background.ts', 'background': './src/background.ts',
'content/autofill': './src/content/autofill.js', 'content/autofill': './src/content/autofill.js',
'content/autofiller': './src/content/autofiller.ts', 'content/autofiller': './src/content/autofiller.ts',
'content/downloader': './src/content/downloader.ts',
'content/notificationBar': './src/content/notificationBar.ts', 'content/notificationBar': './src/content/notificationBar.ts',
'content/shortcuts': './src/content/shortcuts.ts', 'content/shortcuts': './src/content/shortcuts.ts',
'notification/bar': './src/notification/bar.js', 'notification/bar': './src/notification/bar.js',