Skip to content

Commit

Permalink
fix: Correctly handle Chinese file names
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Mar 20, 2024
1 parent 2cff7f0 commit d23e8da
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ chrome.storage.local.get(['host', 'token', 'enableNotification'], function (data
token: token
});

chrome.downloads.onCreated.addListener(async function (downloadItem) {
chrome.downloads.cancel(downloadItem.id);
chrome.downloads.onDeterminingFilename.addListener(async function (item) {
await chrome.downloads.cancel(item.id)
if (item.state === "complete") {
await chrome.downloads.removeFile(item.id);
}

const downloadUrl = item.finalUrl;

try {
await client.createTask({
req: {
url: downloadItem.finalUrl,
url: downloadUrl,
},
opt: {
name: item.filename,
selectFiles: [0]
}
});
chrome.notifications.create({
await chrome.notifications.create({
type: 'basic',
iconUrl: "icons/icon_48.png",
title: 'Create task success',
message: 'Size: ' + (downloadItem.fileSize / (1024 * 1024)).toFixed(2) + 'MB',
message: 'Size: ' + (item.fileSize / (1024 * 1024)).toFixed(2) + 'MB',
});
} catch (error) {
chrome.notifications.create({
await chrome.notifications.create({
type: 'basic',
iconUrl: "icons/icon_48.png",
title: 'Error when create task',
Expand Down

0 comments on commit d23e8da

Please sign in to comment.