From b0bf5a3c2992cc666d6a2f84adab3a660b83571d Mon Sep 17 00:00:00 2001 From: jeasonnow Date: Thu, 20 Jul 2023 11:15:56 +0800 Subject: [PATCH] fix: fix some datauri download bug --- plugins/pakeCliDevPlugin.js | 6 +----- src-tauri/src/inject/event.js | 11 +++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/pakeCliDevPlugin.js b/plugins/pakeCliDevPlugin.js index 367e4ad..33f8f16 100644 --- a/plugins/pakeCliDevPlugin.js +++ b/plugins/pakeCliDevPlugin.js @@ -30,11 +30,7 @@ export default function pakeCliDevPlugin() { console.log(chalk.yellow(`cli running end with code: ${code}`)); if (devHasStarted) return; devHasStarted = true; - - const devCommand = 'npm'; - const devArgs = ['run', 'tauri', 'dev', '--', '--config', './src-tauri/.pake/tauri.conf.json', '--features', 'cli-build']; - devChildProcess = spawn(devCommand, devArgs, {detached: true}); - + devChildProcess = await exec('npm run tauri dev -- --config ./src-tauri/.pake/tauri.conf.json --features cli-build'); devChildProcess.stdout.on('data', (data) => { console.log(chalk.green(data.toString())); diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js index b132cec..8907880 100644 --- a/src-tauri/src/inject/event.js +++ b/src-tauri/src/inject/event.js @@ -137,6 +137,8 @@ document.addEventListener('DOMContentLoaded', () => { } }); + const specialDownloadProtocal = ['blob', 'data']; + const detectAnchorElementClick = (e) => { const anchorElement = e.target.closest('a'); if (anchorElement && anchorElement.href) { @@ -164,7 +166,7 @@ document.addEventListener('DOMContentLoaded', () => { e.metaKey || e.ctrlKey || isDownloadLink(absoluteUrl)) && - !externalDownLoadLink() && !url.startsWith("blob") + !externalDownLoadLink() && specialDownloadProtocal.every(protocal => !absoluteUrl.startsWith(protocal)) ) { e.preventDefault(); invoke('download_file', { @@ -262,7 +264,7 @@ function convertBlobUrlToBinary(blobUrl) { }); } -function downladFromDataUri(dataURI) { +function downladFromDataUri(dataURI, filename) { const byteString = atob(dataURI.split(',')[1]); // write the bytes of the string to an ArrayBuffer const bufferArray = new ArrayBuffer(byteString.length); @@ -305,11 +307,12 @@ function detectDownloadByCreateAnchor() { // use addEventListener to avoid overriding the original click event. anchorEle.addEventListener('click', () => { const url = anchorEle.href; + const filename = anchorEle.download || getFilenameFromUrl(url); if (window.blobToUrlCaches.has(url)) { - downloadFromBlobUrl(url, anchorEle.download || getFilenameFromUrl(url)); + downloadFromBlobUrl(url, filename); // case: downoload from dataURL -> convert dataURL -> } else if (url.startsWith('data:')) { - downladFromDataUri(url); + downladFromDataUri(url, filename); } }, true);