Repository navigation
feat: download manager #256
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
50a633f
a4c620e
f0de032
e2c63b4
fc594c2
5c22e32
999787e
c240dd2
c08a893
644e5b1
26df532
d34a590
ac210f4
84335aa
69c9fb9
9aa4d99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||||||||||
| import { ipcMain, shell } from "electron"; | ||||||||||||||||||||||||||
| import { downloadsController } from "@/controllers/downloads-controller"; | ||||||||||||||||||||||||||
| import { deleteDownloadRecord, getDownloadRecord, listDownloads } from "@/saving/downloads"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:list", () => { | ||||||||||||||||||||||||||
| return downloadsController.listDownloads(); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:get", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| return downloadsController.getDownload(downloadId); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:pause", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| return downloadsController.pauseDownload(downloadId); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:resume", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| return downloadsController.resumeDownload(downloadId); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:cancel", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| return downloadsController.cancelDownload(downloadId); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:show-in-folder", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| const record = getDownloadRecord(downloadId); | ||||||||||||||||||||||||||
| if (!record?.savePath) return false; | ||||||||||||||||||||||||||
| shell.showItemInFolder(record.savePath); | ||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:open-file", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| const record = getDownloadRecord(downloadId); | ||||||||||||||||||||||||||
| if (!record?.savePath || record.state !== "completed") return false; | ||||||||||||||||||||||||||
| shell.openPath(record.savePath); | ||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
Comment on lines
+38
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Await and check the result-ipcMain.handle("downloads:open-file", (_event, downloadId: string) => {
+ipcMain.handle("downloads:open-file", async (_event, downloadId: string) => {
const record = getDownloadRecord(downloadId);
if (!record?.savePath || record.state !== "completed") return false;
- shell.openPath(record.savePath);
- return true;
+ const error = await shell.openPath(record.savePath);
+ return error === "";
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:remove-record", (_event, downloadId: string) => { | ||||||||||||||||||||||||||
| return deleteDownloadRecord(downloadId); | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ipcMain.handle("downloads:clear-completed", () => { | ||||||||||||||||||||||||||
| const downloads = listDownloads(); | ||||||||||||||||||||||||||
| for (const dl of downloads) { | ||||||||||||||||||||||||||
| if (dl.state === "completed" || dl.state === "cancelled") { | ||||||||||||||||||||||||||
| deleteDownloadRecord(dl.id); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { ThemeProvider } from "@/components/main/theme"; | ||
| import { RouteConfigType } from "@/types/routes"; | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { ReactNode, useState } from "react"; | ||
|
|
||
| function DownloadsQueryProvider({ children }: { children: ReactNode }) { | ||
| const [queryClient] = useState( | ||
| () => | ||
| new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| staleTime: 5_000 | ||
| } | ||
| } | ||
| }) | ||
| ); | ||
| return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>; | ||
| } | ||
|
|
||
| export const RouteConfig: RouteConfigType = { | ||
| Providers: ({ children }: { children: ReactNode }) => { | ||
| return ( | ||
| <DownloadsQueryProvider> | ||
| <ThemeProvider forceTheme="dark">{children}</ThemeProvider> | ||
| </DownloadsQueryProvider> | ||
| ); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell.openPathresult not awaited — errors silently swallowedshell.openPath()returns aPromise<string>where an empty string means success and a non-empty string is the OS error message. Because the promise is not awaited, any failure (no associated application, permission denied, file moved/deleted since the record was saved) is silently dropped. The handler always returnstruewhenever it finds a completed record, so the renderer'sif (!ok) toast.error("Could not open file")guard is never triggered — users get no feedback when the open fails.