Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update downloads-manager extension #16042

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
6 changes: 5 additions & 1 deletion extensions/downloads-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Downloads Manager Changelog

## [Add show hidden files preference] - {PR_MERGE_DATE}
## [Add file order preference] - 2025-01-07

- Added a preference to sort files by added, modified, or created time in the `Manage Downloads` command.

## [Add show hidden files preference] - 2024-12-22

- Added a preference to show hidden files in the `Manage Downloads` command

Expand Down
23 changes: 23 additions & 0 deletions extensions/downloads-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@
"description": "Show hidden files in the folder",
"required": false,
"default": false
},
{
"type": "dropdown",
"name": "fileOrder",
"label": "File Order",
"title": "File Order",
"description": "The order of the files in the folder",
"required": false,
"default": "modifiedTime",
"data": [
{
"title": "Modified Time",
"value": "modifiedTime"
},
{
"title": "Add Time",
"value": "addTime"
},
{
"title": "Create Time",
"value": "createTime"
}
]
}
]
},
Expand Down
23 changes: 20 additions & 3 deletions extensions/downloads-manager/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,34 @@ import untildify from "untildify";
const preferences = getPreferenceValues();
export const downloadsFolder = untildify(preferences.downloadsFolder ?? "~/Downloads");
const showHiddenFiles = preferences.showHiddenFiles;
const fileOrder = preferences.fileOrder;

export function getDownloads() {
const files = readdirSync(downloadsFolder);
return files
.filter((file) => showHiddenFiles || !file.startsWith("."))
.map((file) => {
const path = join(downloadsFolder, file);
const lastModifiedAt = statSync(path).mtime;
return { file, path, lastModifiedAt };
const stats = statSync(path);
return {
file,
path,
lastModifiedAt: stats.mtime,
createdAt: stats.ctime,
addedAt: stats.atime,
};
})
.sort((a, b) => b.lastModifiedAt.getTime() - a.lastModifiedAt.getTime());
.sort((a, b) => {
switch (fileOrder) {
case "addTime":
return b.addedAt.getTime() - a.addedAt.getTime();
case "createTime":
return b.createdAt.getTime() - a.createdAt.getTime();
case "modifiedTime":
default:
return b.lastModifiedAt.getTime() - a.lastModifiedAt.getTime();
}
});
}

export function getLatestDownload() {
Expand Down