fix backgound.js listener callback, take 3

This commit is contained in:
simon 2022-04-04 11:58:50 +07:00
parent 1dd2d503cc
commit aff7c50f94
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -116,21 +116,25 @@ async function downloadLink(toDownload) {
} }
// event listener for messages from script.js and popup.js // process and return message if needed
browserType.runtime.onMessage.addListener( function handleMessage(request, sender, sendResponse) {
(data, sender) => { console.log("message background.js listener: " + JSON.stringify(request));
console.log("message background.js listener: " + JSON.stringify(data))
if (data.verify === true) { if (request.verify === true) {
let response = verifyConnection() let response = verifyConnection();
return Promise.resolve(response); response.then(message => {
} else if (data.youtube) { sendResponse(message);
setYoutubeLink(data) })
} else if (data.download) { } else if (request.youtube) {
let response = downloadLink(data.download.url) setYoutubeLink(request)
return Promise.resolve(response); } else if (request.download) {
let response = downloadLink(request.download.url);
response.then(message => {
sendResponse(message)
})
} }
return false; return true;
} }
);
browserType.runtime.onMessage.addListener(handleMessage);