Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c8b49b56 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Let download update timer only run when there's running downloads

Currently we have a 1000ms timer running querying for running downloads whenever the extension is loaded.

Differential Revision: https://phabricator.kde.org/D14226
parent 6138ef1b
......@@ -314,13 +314,28 @@ addRuntimeCallback("mpris", ["metadata", "callbacks"], function (message, sender
//
var activeDownloads = []
var downloadUpdateInterval = 0;
setInterval(function() {
function startSendingDownloadUpdates() {
if (!downloadUpdateInterval) {
downloadUpdateInterval = setInterval(sendDownloadUpdates, 1000);
}
}
function stopSendingDownloadUpdates() {
if (downloadUpdateInterval) {
clearInterval(downloadUpdateInterval);
downloadUpdateInterval = 0;
}
}
function sendDownloadUpdates() {
chrome.downloads.search({
state: 'in_progress',
paused: false
}, function (results) {
if (!results.length) {
stopSendingDownloadUpdates();
return;
}
......@@ -341,7 +356,7 @@ setInterval(function() {
port.postMessage({subsystem: "downloads", event: "update", download: payload});
});
});
}, 1000);
}
// only forward certain download properties back to our host
var whitelistedDownloadProperties = [
......@@ -358,6 +373,7 @@ chrome.downloads.onCreated.addListener(function (download) {
var filteredDownload = filterObject(download, whitelistedDownloadProperties);
activeDownloads.push(download.id);
startSendingDownloadUpdates();
port.postMessage({subsystem: "downloads", event: "created", download: filteredDownload});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment