From eec577372c824f35aa3705a2782b7a899622d571 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 21 Aug 2019 16:50:15 -0400 Subject: [PATCH] include downloader script and page --- gulpfile.js | 5 +++- src/content/downloader.ts | 26 +++++++++++++++++++++ src/downloader/downloader.ts | 29 +----------------------- src/safari/app/desktop/safari/Info.plist | 4 ++++ webpack.config.js | 1 + 5 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 src/content/downloader.ts diff --git a/gulpfile.js b/gulpfile.js index 09b6a43e81..9f130d3053 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,6 +31,9 @@ const filters = { '!build/safari/**/*', '!build/downloader/**/*' ], + safariDir: [ + '!build/safari/**/*' + ], webExt: [ '!build/manifest.json' ], @@ -215,7 +218,7 @@ function safariAppCopyBuild(source, dest) { return new Promise((resolve, reject) => { gulp.src(source) .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))) .pipe(gulp.dest(dest)) .on('end', resolve); diff --git a/src/content/downloader.ts b/src/content/downloader.ts new file mode 100644 index 0000000000..eb1517f2fd --- /dev/null +++ b/src/content/downloader.ts @@ -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); +}); diff --git a/src/downloader/downloader.ts b/src/downloader/downloader.ts index a840309f12..4c7473764e 100644 --- a/src/downloader/downloader.ts +++ b/src/downloader/downloader.ts @@ -1,30 +1,3 @@ document.addEventListener('DOMContentLoaded', () => { - const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 && - 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); - } + // TODO }); diff --git a/src/safari/app/desktop/safari/Info.plist b/src/safari/app/desktop/safari/Info.plist index 5d5c054f03..edd7c46e7c 100644 --- a/src/safari/app/desktop/safari/Info.plist +++ b/src/safari/app/desktop/safari/Info.plist @@ -53,6 +53,10 @@ Script app/content/shortcuts.js + + Script + app/content/downloader.js + SFSafariToolbarItem diff --git a/webpack.config.js b/webpack.config.js index 3e25f5e394..43ba3cbd62 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -145,6 +145,7 @@ const config = { 'background': './src/background.ts', 'content/autofill': './src/content/autofill.js', 'content/autofiller': './src/content/autofiller.ts', + 'content/downloader': './src/content/downloader.ts', 'content/notificationBar': './src/content/notificationBar.ts', 'content/shortcuts': './src/content/shortcuts.ts', 'notification/bar': './src/notification/bar.js',