Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: download manager UI
  • Loading branch information
iamEvanYT committed Apr 7, 2026
commit e2c63b4cd2119cc7167583e7463a3ec4593ce844
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export const STATIC_DOMAINS: StaticDomainInfo[] = [
route: "history"
}
},
{
protocol: "flow",
hostname: "downloads",
actual: {
type: "route",
route: "downloads"
}
},
{
protocol: "flow",
hostname: "bangs",
Expand Down
50 changes: 50 additions & 0 deletions src/main/ipc/browser/downloads.ts
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 shell.openPath result not awaited — errors silently swallowed

shell.openPath() returns a Promise<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 returns true whenever it finds a completed record, so the renderer's if (!ok) toast.error("Could not open file") guard is never triggered — users get no feedback when the open fails.

Suggested change
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;
});
ipcMain.handle("downloads:open-file", async (_event, downloadId: string) => {
const record = getDownloadRecord(downloadId);
if (!record?.savePath || record.state !== "completed") return false;
const err = await shell.openPath(record.savePath);
return err === "";
});

Comment on lines +38 to +43

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

shell.openPath result is not awaited, success always returned.

shell.openPath() returns Promise<string> where an empty string indicates success and a non-empty string contains an error message. The current code returns true immediately without checking the result, so failures are silently ignored and the renderer always receives success.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
});
ipcMain.handle("downloads:open-file", async (_event, downloadId: string) => {
const record = getDownloadRecord(downloadId);
if (!record?.savePath || record.state !== "completed") return false;
const error = await shell.openPath(record.savePath);
return error === "";
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/ipc/browser/downloads.ts` around lines 38 - 43, The handler for
"downloads:open-file" currently calls shell.openPath(record.savePath) but
doesn’t await its Promise, so it always returns true; modify the ipcMain.handle
callback (the "downloads:open-file" handler that uses getDownloadRecord) to
await shell.openPath(record.savePath) and check its returned string (empty =
success, non-empty = error message) and return true only on success and false on
error (optionally log or process the error string before returning false).


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);
}
}
});
1 change: 1 addition & 0 deletions src/main/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "@/ipc/browser/pinned-tabs";
import "@/ipc/browser/page";
import "@/ipc/browser/navigation";
import "@/ipc/browser/history";
import "@/ipc/browser/downloads";
import "@/ipc/browser/interface";
import "@/ipc/browser/find-in-page";
import "@/ipc/window/omnibox";
Expand Down
5 changes: 5 additions & 0 deletions src/main/saving/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export function listDownloads(): DownloadRow[] {
return getDb().select().from(schema.downloads).orderBy(desc(schema.downloads.updatedAt)).all();
}

export function deleteDownloadRecord(downloadId: string): boolean {
const result = getDb().delete(schema.downloads).where(eq(schema.downloads.id, downloadId)).run();
return result.changes > 0;
}

export function reconcileDownloadsOnStartup(): void {
getDb()
.update(schema.downloads)
Expand Down
36 changes: 35 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { FlowShortcutsAPI, ShortcutsData } from "~/flow/interfaces/app/shortcuts
import { FlowFindInPageAPI, FindInPageResult } from "~/flow/interfaces/browser/find-in-page";
import { FlowHistoryAPI } from "~/flow/interfaces/browser/history";
import { FlowPasskeyAPI } from "~/flow/interfaces/browser/passkey";
import { FlowDownloadsAPI } from "~/flow/interfaces/browser/downloads";
import type { ConditionalPasskeyRequest, PasskeyCredential } from "~/types/passkey";

// const isIFrame = !process.isMainFrame;
Expand Down Expand Up @@ -76,14 +77,15 @@ function hasPermission(permission: Permission) {
// Extensions
const isExtensions = isLocation("flow:", "extensions");
const isHistoryPage = isLocation("flow:", "history");
const isDownloadsPage = isLocation("flow:", "downloads");

switch (permission) {
case "all":
return true;
case "app":
return isInternalProtocols || isExtensions;
case "browser":
return isBrowserUI || isOmnibox || isHistoryPage;
return isBrowserUI || isOmnibox || isHistoryPage || isDownloadsPage;
case "session":
return isFlowInternalProtocol || isOmnibox || isBrowserUI;
case "settings":
Expand Down Expand Up @@ -407,6 +409,37 @@ const passkeyAPI: FlowPasskeyAPI = {
}
};

// DOWNLOADS API //
const downloadsAPI: FlowDownloadsAPI = {
list: async () => {
return ipcRenderer.invoke("downloads:list");
},
get: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:get", downloadId);
},
pause: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:pause", downloadId);
},
resume: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:resume", downloadId);
},
cancel: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:cancel", downloadId);
},
showInFolder: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:show-in-folder", downloadId);
},
openFile: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:open-file", downloadId);
},
removeRecord: async (downloadId: string) => {
return ipcRenderer.invoke("downloads:remove-record", downloadId);
},
clearCompleted: async () => {
return ipcRenderer.invoke("downloads:clear-completed");
}
};

// INTERFACE API //
const interfaceAPI: FlowInterfaceAPI = {
setWindowButtonPosition: (position: { x: number; y: number }) => {
Expand Down Expand Up @@ -781,6 +814,7 @@ const flowAPI: typeof flow = {
navigation: wrapAPI(navigationAPI, "browser"),
history: wrapAPI(historyAPI, "browser"),
passkey: wrapAPI(passkeyAPI, "browser"),
downloads: wrapAPI(downloadsAPI, "browser"),
interface: wrapAPI(interfaceAPI, "browser", {
moveWindowTo: "all",
resizeWindowTo: "all"
Expand Down
28 changes: 28 additions & 0 deletions src/renderer/src/routes/downloads/config.tsx
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>
);
}
};
Loading