Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/browser/app/profile/features.inc
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,6 @@ pref('zen.splitView.rearrange-hover-size', 24);
// Zen Download Animations
pref('zen.downloads.download-animation', true);
pref('zen.downloads.download-animation-duration', 1000); // ms

// Zen Download Notifications
pref('zen.downloads.download-notifications', true);
48 changes: 48 additions & 0 deletions src/zen/downloads/ZenDownloadAnimation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
const list = await Downloads.getList(Downloads.ALL);
list.addView({
onDownloadAdded: this.#handleNewDownload.bind(this),
onDownloadChanged: download => {
if (download.succeeded) {
this.#handleDownloadComplete(download);
} else if (download.canceled) {
this.#handleDownloadCanceled(download);
} else if (download.error) {
this.#handleDownloadFailed(download);
}
},
Comment on lines +37 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe more cool:

if (download.succeeded) {
  this.#handleDownloadComplete(download);
}

if (download.canceled) {
  this.#handleDownloadCanceled(download);
} 

if (download.error) {
  this.#handleDownloadFailed(download);
}

});
} catch (error) {
console.error(
Expand All @@ -57,6 +66,45 @@
this.#animateDownload(this.#lastClickPosition);
}

async #handleDownloadComplete(download) {
if (!Services.prefs.getBoolPref('zen.downloads.download-notifications')) {
return;
}
const title = await document.l10n.formatValue('zen-download-complete') ?? 'Download Complete';
const body = await document.l10n.formatValue('zen-download-complete-body', { filename: download.target.path }) ??
`File "${download.target.path}" has finished downloading.`;
const notification = new Notification(title, {
body: body,
icon: 'chrome://browser/skin/downloads/download.svg',
});
}

async #handleDownloadCanceled(download) {
if (!Services.prefs.getBoolPref('zen.downloads.download-notifications')) {
return;
}
const title = await document.l10n.formatValue('zen-download-canceled') ?? 'Download Canceled';
const body = await document.l10n.formatValue('zen-download-canceled-body', { filename: download.target.path }) ??
`File "${download.target.path}" download was canceled.`;
const notification = new Notification(title, {
body: body,
icon: 'chrome://browser/skin/downloads/download.svg',
});
}

async #handleDownloadFailed(download) {
if (!Services.prefs.getBoolPref('zen.downloads.download-notifications')) {
return;
}
const title = await document.l10n.formatValue('zen-download-failed') ?? 'Download Failed';
const body = await document.l10n.formatValue('zen-download-failed-body', { filename: download.target.path }) ??
`Failed to download file "${download.target.path}".`;
const notification = new Notification(title, {
body: body,
icon: 'chrome://browser/skin/downloads/download.svg',
});
}

#animateDownload(startPosition) {
let animationElement = document.querySelector('zen-download-animation');

Expand Down