mirror of
https://github.com/zen-browser/desktop.git
synced 2026-09-25 05:36:26 +00:00
gh-15533: Toggle 'open when done' for library downloads (gh-15534)
This commit is contained in:
@@ -78,6 +78,7 @@ library-downloads-opening-in = { PLATFORM() ->
|
||||
[windows] Opening in File Explorer…
|
||||
*[other] Opening in file manager…
|
||||
}
|
||||
library-downloads-open-when-done = Opens when finished
|
||||
library-downloads-cancel-button =
|
||||
.title = Cancel download
|
||||
library-downloads-filter-title = Filter Downloads…
|
||||
|
||||
@@ -235,7 +235,31 @@ class ZenLibraryDownloadStack {
|
||||
.finally(() => download.target.refresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} download
|
||||
* @returns {boolean} Whether it will be opened as soon as it is here
|
||||
*/
|
||||
#opensWhenDone(download) {
|
||||
return !download.stopped && !!download.launchWhenSucceeded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clicking a download that is still coming in asks for it to be opened as
|
||||
* soon as it is here, the way the downloads panel does.
|
||||
*
|
||||
* @param {object} download
|
||||
*/
|
||||
#toggleOpenWhenDone(download) {
|
||||
download.launchWhenSucceeded = !download.launchWhenSucceeded;
|
||||
download._launchedFromPanel = download.launchWhenSucceeded;
|
||||
this.#updateList();
|
||||
}
|
||||
|
||||
#openDownload(download) {
|
||||
if (!download.stopped) {
|
||||
this.#toggleOpenWhenDone(download);
|
||||
return;
|
||||
}
|
||||
if (download.succeeded) {
|
||||
lazy.DownloadsCommon.openDownload(download).catch(console.error);
|
||||
} else if (download.source?.url) {
|
||||
@@ -274,14 +298,29 @@ class ZenLibraryDownloadStack {
|
||||
);
|
||||
entry.querySelector(".zen-library-download-list-title").textContent =
|
||||
this.#fileName(download);
|
||||
entry.querySelector(".zen-library-download-list-subtitle").textContent =
|
||||
this.#statusText(download);
|
||||
const subtitle = entry.querySelector(
|
||||
".zen-library-download-list-subtitle"
|
||||
);
|
||||
if (this.#opensWhenDone(download)) {
|
||||
this.#window.document.l10n.setAttributes(
|
||||
subtitle,
|
||||
"library-downloads-open-when-done"
|
||||
);
|
||||
} else {
|
||||
subtitle.removeAttribute("data-l10n-id");
|
||||
subtitle.textContent = this.#statusText(download);
|
||||
}
|
||||
entry.toggleAttribute("downloading", !download.stopped);
|
||||
entry.toggleAttribute("open-when-done", this.#opensWhenDone(download));
|
||||
});
|
||||
this.#tabs?.style.setProperty(
|
||||
"--zen-library-stack-height",
|
||||
`${this.#list.getBoundingClientRect().height}px`
|
||||
);
|
||||
this.#window
|
||||
.promiseDocumentFlushed(() => this.#list.getBoundingClientRect().height)
|
||||
.then(height => {
|
||||
this.#tabs?.style.setProperty(
|
||||
"--zen-library-stack-height",
|
||||
`${height}px`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#updateBadge(badge, download) {
|
||||
|
||||
@@ -326,7 +326,34 @@ export class ZenLibraryDownloadsSection extends ZenLibrarySearchSection {
|
||||
lazy.DownloadsCommon.showDownloadedFile(this.#file(download));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a download that is still coming in will be opened the moment it
|
||||
* finishes.
|
||||
*
|
||||
* @param {object} download
|
||||
* @returns {boolean}
|
||||
*/
|
||||
#opensWhenDone(download) {
|
||||
return !download.stopped && !!download.launchWhenSucceeded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clicking a download that is still coming in asks for it to be opened as
|
||||
* soon as it is here, the way the downloads panel does.
|
||||
*
|
||||
* @param {object} download
|
||||
*/
|
||||
#toggleOpenWhenDone(download) {
|
||||
download.launchWhenSucceeded = !download.launchWhenSucceeded;
|
||||
download._launchedFromPanel = download.launchWhenSucceeded;
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
#onRowClick(download) {
|
||||
if (!download.stopped) {
|
||||
this.#toggleOpenWhenDone(download);
|
||||
return;
|
||||
}
|
||||
if (!this.#hasFile(download)) {
|
||||
return;
|
||||
}
|
||||
@@ -516,15 +543,22 @@ export class ZenLibraryDownloadsSection extends ZenLibrarySearchSection {
|
||||
// Rendering
|
||||
|
||||
#renderSubtitle(download) {
|
||||
const statusNode =
|
||||
download === this.#openingDownload
|
||||
? html`<span
|
||||
class="zen-library-download-status"
|
||||
data-l10n-id="library-downloads-opening-in"
|
||||
></span>`
|
||||
: html`<span class="zen-library-download-status"
|
||||
>${this.#statusText(download)}</span
|
||||
>`;
|
||||
let statusNode;
|
||||
if (download === this.#openingDownload) {
|
||||
statusNode = html`<span
|
||||
class="zen-library-download-status"
|
||||
data-l10n-id="library-downloads-opening-in"
|
||||
></span>`;
|
||||
} else if (this.#opensWhenDone(download)) {
|
||||
statusNode = html`<span
|
||||
class="zen-library-download-status"
|
||||
data-l10n-id="library-downloads-open-when-done"
|
||||
></span>`;
|
||||
} else {
|
||||
statusNode = html`<span class="zen-library-download-status"
|
||||
>${this.#statusText(download)}</span
|
||||
>`;
|
||||
}
|
||||
return html`
|
||||
<span class="zen-library-row-subtitle">
|
||||
${statusNode}
|
||||
@@ -584,6 +618,7 @@ export class ZenLibraryDownloadsSection extends ZenLibrarySearchSection {
|
||||
?pending=${pending}
|
||||
?indeterminate=${pending && !download.hasProgress}
|
||||
?paused=${pending && download.stopped}
|
||||
?open-when-done=${this.#opensWhenDone(download)}
|
||||
?opening=${download === this.#openingDownload}
|
||||
@click=${() => this.#onRowClick(download)}
|
||||
@contextmenu=${event => {
|
||||
|
||||
@@ -882,6 +882,11 @@ zen-library:not([open]) :is(.zen-library-search-header, .zen-library-filter-head
|
||||
display: none;
|
||||
}
|
||||
|
||||
.zen-library-row[pending][open-when-done]:not(:hover)
|
||||
.zen-library-download-status {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.zen-library-row[pending]:not(:hover) .zen-library-row-subtitle::before {
|
||||
content: "";
|
||||
display: block;
|
||||
|
||||
Reference in New Issue
Block a user