Merge branch 'master' of https://github.com/tw93/pake
This commit is contained in:
14
README.md
14
README.md
@@ -269,6 +269,13 @@ Pake's development can not be without these Hackers. They contributed a lot of c
|
||||
<sub><b>Pake Actions</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/jeasonnow">
|
||||
<img src="https://avatars.githubusercontent.com/u/16950207?v=4" width="90;" alt="jeasonnow"/>
|
||||
<br />
|
||||
<sub><b>Santree</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/QingZ11">
|
||||
<img src="https://avatars.githubusercontent.com/u/38887077?v=4" width="90;" alt="QingZ11"/>
|
||||
@@ -283,13 +290,6 @@ Pake's development can not be without these Hackers. They contributed a lot of c
|
||||
<sub><b>孟世博</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/jeasonnow">
|
||||
<img src="https://avatars.githubusercontent.com/u/16950207?v=4" width="90;" alt="jeasonnow"/>
|
||||
<br />
|
||||
<sub><b>Santree</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/2nthony">
|
||||
<img src="https://avatars.githubusercontent.com/u/19513289?v=4" width="90;" alt="2nthony"/>
|
||||
|
||||
34
src-tauri/src/inject/event.js
vendored
34
src-tauri/src/inject/event.js
vendored
@@ -156,6 +156,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
|
||||
|
||||
// Process download links for Rust to handle.
|
||||
// If the download attribute is set, the download attribute is used as the file name.
|
||||
if (
|
||||
@@ -261,29 +262,32 @@ function convertBlobUrlToBinary(blobUrl) {
|
||||
});
|
||||
}
|
||||
|
||||
function downloadFromBlobUrl(blobUrl, filename) {
|
||||
const tauri = window.__TAURI__;
|
||||
convertBlobUrlToBinary(blobUrl).then((binary) => {
|
||||
console.log('binary', binary);
|
||||
tauri.fs.writeBinaryFile(filename, binary, {
|
||||
dir: tauri.fs.BaseDirectory.Download,
|
||||
}).then(() => {
|
||||
window.pakeToast('Download successful, saved to download directory~');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// detect blob download by createElement("a")
|
||||
function detectDownloadByCreateAnchor() {
|
||||
const createEle = document.createElement;
|
||||
document.createElement = (el) => {
|
||||
if (el !== "a") return createEle.call(document, el);
|
||||
const anchorEle = createEle.call(document, el);
|
||||
const anchorClick = anchorEle.click;
|
||||
|
||||
Object.defineProperties(anchorEle, {
|
||||
click: {
|
||||
get: () => {
|
||||
if (anchorEle.href && anchorEle.href.includes('blob:')) {
|
||||
const url = anchorEle.href;
|
||||
convertBlobUrlToBinary(url).then((binary) => {
|
||||
tauri.fs.writeBinaryFile(anchorEle.download || getFilenameFromUrl(url), binary, {
|
||||
dir: tauri.fs.BaseDirectory.Download,
|
||||
});
|
||||
});
|
||||
}
|
||||
return anchorClick.bind(anchorEle);
|
||||
}
|
||||
// use addEventListener to avoid overriding the original click event.
|
||||
anchorEle.addEventListener('click', () => {
|
||||
const url = anchorEle.href;
|
||||
if (window.blobToUrlCaches.has(url)) {
|
||||
downloadFromBlobUrl(url, anchorEle.download || getFilenameFromUrl(url));
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return anchorEle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user