Skip to content

Commit

Permalink
update downloads delete file command to 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aminomancer committed Jan 6, 2022
1 parent 14a0e01 commit 0a12381
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
22 changes: 9 additions & 13 deletions JS/downloadsDeleteFileCommand.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Downloads Delete File Command
// @version 1.0.1
// @version 1.0.2
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Adds a new "Delete" menuitem when right-clicking a download in the downloads panel or the downloads manager. This will delete the downloaded file from disk. It's important since the ability to "temporarily" download files with Firefox is being removed as part of bug 1733587 to reduce the risk of data loss. When you choose to "open" a file instead of "save" it, Firefox will no longer save the file in your Temp folder, but rather in your chosen Downloads folder. So, being able to clean up these files from the context menu is a nice feature. This will most likely be released in Firefox (see bug 1745624), but I did a lot of the testing for it with an autoconfig script, so it isn't any extra work to publish this here, at least until it makes it into a release build. When you download a version of Firefox that includes the menuitem, you can just delete this script.
Expand Down Expand Up @@ -29,6 +29,11 @@
}),
context.querySelector(".downloadRemoveFromHistoryMenuItem")
);
let clearDownloads = context.querySelector(
`[data-l10n-id="downloads-cmd-clear-downloads"]`
);
if (clearDownloads.getAttribute("accesskey") === "D")
clearDownloads.setAttribute("accesskey", "C");

// Add the class method for the command.
if (
Expand All @@ -40,16 +45,11 @@
async function downloadsCmd_deleteFile() {
let { download } = this;
let { path } = download.target;
let { succeeded } = download;
let indicator = DownloadsCommon.getIndicatorData(this.element.ownerGlobal);
// Remove the download view.
try {
await PlacesUtils.history.remove(download.source.url);
} catch (ex) {
Cu.reportError(ex);
}
let list = await Downloads.getList(Downloads.ALL);
await list.remove(download);
if (download.succeeded) {
await DownloadsCommon.deleteDownload(download);
if (succeeded) {
// Temp files are made "read-only" by DownloadIntegration.downloadDone, so reset the permission bits to read/write.
// This won't be necessary after 1733587 since Downloads won't ever be temporary.
let info = await IOUtils.stat(path);
Expand All @@ -58,10 +58,6 @@
ignoreAbsent: true,
recursive: info.type === "directory",
});
} else {
// Bail out of download and remove partial data or final file.
download.cancel().catch(() => {});
await download.finalize(true);
}
if (!indicator._hasDownloads)
indicator.attention = DownloadsCommon.ATTENTION_NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ var DownloadsViewUI = {
let { preferredAction, useSystemDefault } = mimeInfo ? mimeInfo : {};

// Hide the "Delete" item if there's no file data to delete.
contextMenu.querySelector(".downloadDeleteFileMenuItem").hidden =
!(download.target.exists || download.target.partFileExists);
contextMenu.querySelector(".downloadDeleteFileMenuItem").hidden = !(
download.target.exists || download.target.partFileExists
);

// Hide the "use system viewer" and "always use system viewer" items
// if the feature is disabled or this download doesn't support it:
Expand Down Expand Up @@ -976,10 +977,12 @@ DownloadsViewUI.DownloadElementShell.prototype = {
case "downloadsCmd_alwaysOpenSimilarFiles":
// This property is false if the download did not succeed.
return this.download.target.exists;

case "downloadsCmd_show":
case "downloadsCmd_deleteFile":
let { target } = this.download;
return target.exists || target.partFileExists;

case "downloadsCmd_delete":
case "cmd_delete":
// We don't want in-progress downloads to be removed accidentally.
Expand Down Expand Up @@ -1072,16 +1075,12 @@ DownloadsViewUI.DownloadElementShell.prototype = {
async downloadsCmd_deleteFile() {
let { download } = this;
let { path } = download.target;
let { succeeded } = download;
let indicator = DownloadsCommon.getIndicatorData(this.element.ownerGlobal);
// Remove the download view.
try {
await PlacesUtils.history.remove(download.source.url);
} catch (ex) {
Cu.reportError(ex);
}
let list = await Downloads.getList(Downloads.ALL);
await list.remove(download);
if (download.succeeded) {
// Remove the download from the session and history downloads, delete part files.
await DownloadsCommon.deleteDownload(download);
// Delete final files.
if (succeeded) {
// Temp files are made "read-only" by DownloadIntegration.downloadDone, so reset the permission bits to read/write.
// This won't be necessary after 1733587 since Downloads won't ever be temporary.
let info = await IOUtils.stat(path);
Expand All @@ -1090,12 +1089,10 @@ DownloadsViewUI.DownloadElementShell.prototype = {
ignoreAbsent: true,
recursive: info.type === "directory",
});
} else {
// Bail out of download and remove partial data or final file.
download.cancel().catch(() => {});
await download.finalize(true);
}
if (!indicator._hasDownloads) indicator.attention = DownloadsCommon.ATTENTION_NONE;
if (!indicator._hasDownloads) {
indicator.attention = DownloadsCommon.ATTENTION_NONE;
}
},

downloadsCmd_openInSystemViewer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ class DownloadsViewItem extends DownloadsViewUI.DownloadElementShell {
}
// Don't use DownloadsPanel.hidePanel for this method because it will remove
// the view item from the list, which is already sufficient feedback.
};
}

downloadsCmd_showBlockedInfo() {
DownloadsBlockedSubview.toggle(
Expand Down
12 changes: 10 additions & 2 deletions uc-popups.css
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,26 @@ panel[type="autocomplete-richlistbox"]
@-moz-document url("chrome://global/content/pictureinpicture/player.xhtml")
{
.control-item {
backdrop-filter: blur(8px) !important;
/* backdrop-filter has been temporarily disabled by mozilla */
/* backdrop-filter: blur(8px) !important;
background-color: var(--btn-bg-color) !important;
background-image: var(--acrylic-texture), var(--pip-icon) !important;
background-image: var(--acrylic-texture), var(--pip-icon) !important; */
background-color: var(--in-content-button-highlight-dark) !important;
fill: currentColor !important;
-moz-context-properties: fill !important;
color: var(--player-control-icon-fill) !important;
border-radius: 3px !important;
}

body:not(:fullscreen) #controls:hover .control-item {
opacity: 1 !important;
}

#controls[keying] button:focus-visible {
outline-style: auto !important;
box-shadow: 1px 2px 5px #000;
}

#close {
background-size: 80% !important;
--pip-icon: url(chrome://global/skin/icons/close.svg);
Expand Down

0 comments on commit 0a12381

Please sign in to comment.