Skip to content

Commit

Permalink
Add notification on task creation
Browse files Browse the repository at this point in the history
  • Loading branch information
krau committed Mar 15, 2024
1 parent 6c89038 commit 823a8e5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict';

import { Client } from "../node_modules/@gopeed/rest";

chrome.storage.local.get(['host', 'token'], function (data) {
chrome.storage.local.get(['host', 'token', 'enableNotification'], function (data) {
const host = data.host;
const token = data.token;

const client = new Client({
host: host,
token: token
});

chrome.downloads.onCreated.addListener(async function (downloadItem) {
console.log('onCreated', downloadItem.finalUrl);
chrome.downloads.cancel(downloadItem.id);
try {
await client.createTask({
Expand All @@ -22,6 +21,12 @@ chrome.storage.local.get(['host', 'token'], function (data) {
selectFiles: [0]
}
});
chrome.notifications.create({
type: 'basic',
iconUrl: "icons/icon_48.png",
title: 'Create task success',
message: 'Size: ' + (downloadItem.fileSize / (1024 * 1024)).toFixed(2) + 'MB',
});
} catch (error) {
chrome.notifications.create({
type: 'basic',
Expand Down

0 comments on commit 823a8e5

Please sign in to comment.