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: add strikethrough for missing files
  • Loading branch information
iamEvanYT committed Apr 7, 2026
commit 5c22e320ff52e84ca9d13400ccad7d76d6699c05
14 changes: 14 additions & 0 deletions src/main/ipc/browser/downloads.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from "node:fs";
import { ipcMain, shell } from "electron";
import { downloadsController } from "@/controllers/downloads-controller";
import { deleteDownloadRecord, getDownloadRecord, listDownloads } from "@/saving/downloads";
Expand Down Expand Up @@ -48,3 +49,16 @@ ipcMain.handle("downloads:clear-completed", () => {
}
}
});
Comment on lines +51 to +61

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.

🧹 Nitpick | 🔵 Trivial

Consider checking deletion result in clear-completed loop.

deleteDownloadRecord returns a boolean, but the loop ignores individual deletion failures. If a deletion fails, changed is still set to true. This could lead to inconsistent state notifications.

Track actual deletions
 ipcMain.handle("downloads:clear-completed", () => {
   const downloads = listDownloads();
   let changed = false;
   for (const dl of downloads) {
     if (dl.state === "completed" || dl.state === "cancelled") {
-      deleteDownloadRecord(dl.id);
-      changed = true;
+      const deleted = deleteDownloadRecord(dl.id);
+      if (deleted) changed = true;
     }
   }
   if (changed) fireDownloadsChanged();
 });
📝 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:clear-completed", () => {
const downloads = listDownloads();
let changed = false;
for (const dl of downloads) {
if (dl.state === "completed" || dl.state === "cancelled") {
deleteDownloadRecord(dl.id);
changed = true;
}
}
if (changed) fireDownloadsChanged();
});
ipcMain.handle("downloads:clear-completed", () => {
const downloads = listDownloads();
let changed = false;
for (const dl of downloads) {
if (dl.state === "completed" || dl.state === "cancelled") {
const deleted = deleteDownloadRecord(dl.id);
if (deleted) changed = true;
}
}
if (changed) fireDownloadsChanged();
});
🤖 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 51 - 61, The clear-completed
handler currently sets changed = true regardless of whether
deleteDownloadRecord(dl.id) actually succeeded; update the loop in the
ipcMain.handle("downloads:clear-completed") callback to check the boolean result
of deleteDownloadRecord for each dl and only set changed = true when
deleteDownloadRecord(...) returns true, optionally collect/log failed deletions
and avoid firing fireDownloadsChanged() if no records were actually removed;
keep references to listDownloads(), deleteDownloadRecord(), and
fireDownloadsChanged() so the change is localized to that handler.


ipcMain.handle("downloads:check-files-exist", (_event, downloadIds: string[]) => {
const result: Record<string, boolean> = {};
for (const id of downloadIds) {
const record = getDownloadRecord(id);
if (!record?.savePath) {
result[id] = false;
} else {
result[id] = fs.existsSync(record.savePath);
}
}
return result;
});
3 changes: 3 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ const downloadsAPI: FlowDownloadsAPI = {
},
clearCompleted: async () => {
return ipcRenderer.invoke("downloads:clear-completed");
},
checkFilesExist: async (downloadIds: string[]) => {
return ipcRenderer.invoke("downloads:check-files-exist", downloadIds);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function StateIcon({ state, className }: { state: DownloadState; className?: str
}
}

function DownloadRow({ dl }: { dl: DownloadRecord }) {
function DownloadRow({ dl, fileMissing }: { dl: DownloadRecord; fileMissing: boolean }) {
const filename = filenameFromRecord(dl);
const progress = dl.totalBytes > 0 ? Math.round((dl.receivedBytes / dl.totalBytes) * 100) : 0;
const isActive = dl.state === "progressing" || dl.state === "paused";
Expand All @@ -54,7 +54,14 @@ function DownloadRow({ dl }: { dl: DownloadRecord }) {
<div className="flex items-center gap-2 px-2 py-1.5 rounded-sm hover:bg-accent/50 group">
<File className="size-3.5 text-muted-foreground shrink-0" />
<div className="min-w-0 flex-1">
<div className="text-xs text-foreground truncate leading-snug">{filename}</div>
<div
className={cn(
"text-xs text-foreground truncate leading-snug",
fileMissing && "line-through text-muted-foreground"
)}
>
{filename}
</div>
{isActive && dl.totalBytes > 0 ? (
<div className="flex items-center gap-1.5 mt-0.5">
<Progress value={progress} className="h-1 flex-1" />
Expand Down Expand Up @@ -89,7 +96,7 @@ function DownloadRow({ dl }: { dl: DownloadRecord }) {
<X className="size-3" />
</Button>
)}
{dl.state === "completed" && (
{dl.state === "completed" && !fileMissing && (
<Button variant="ghost" size="icon" className="size-5" onClick={handleOpen}>
<ExternalLink className="size-3" />
</Button>
Expand All @@ -102,6 +109,7 @@ function DownloadRow({ dl }: { dl: DownloadRecord }) {
export function DownloadsPopover() {
const [open, setOpen] = useState(false);
const [downloads, setDownloads] = useState<DownloadRecord[]>([]);
const [fileExistence, setFileExistence] = useState<Record<string, boolean>>({});

const { isCurrentSpaceLight } = useSpaces();
const spaceInjectedClasses = cn(isCurrentSpaceLight ? "" : "dark");
Expand All @@ -110,6 +118,13 @@ export function DownloadsPopover() {
try {
const all = await flow.downloads.list();
setDownloads(all);
const idsToCheck = all
.filter((d) => d.state !== "progressing" && d.state !== "paused" && d.savePath)
.map((d) => d.id);
if (idsToCheck.length > 0) {
const existence = await flow.downloads.checkFilesExist(idsToCheck);
setFileExistence(existence);
}
} catch {
// silently ignore
}
Expand Down Expand Up @@ -138,9 +153,7 @@ export function DownloadsPopover() {
<PopoverTrigger asChild>
<Button size="icon" className="size-8 bg-transparent hover:bg-black/10 dark:hover:bg-white/10 relative">
<DownloadIcon strokeWidth={2} className="w-4 h-4 text-black/80 dark:text-white/80" />
{hasActive && (
<span className="absolute top-1 right-1 size-2 rounded-full bg-blue-500 animate-pulse" />
)}
{hasActive && <span className="absolute top-1 right-1 size-2 rounded-full bg-blue-500 animate-pulse" />}
</Button>
</PopoverTrigger>
<PortalPopover.Content className={cn("w-72 p-0 select-none", spaceInjectedClasses)}>
Expand All @@ -152,7 +165,7 @@ export function DownloadsPopover() {
) : (
<div className="py-1 px-1 max-h-64 overflow-y-auto">
{shown.map((dl) => (
<DownloadRow key={dl.id} dl={dl} />
<DownloadRow key={dl.id} dl={dl} fileMissing={dl.id in fileExistence && !fileExistence[dl.id]} />
))}
</div>
)}
Expand Down
45 changes: 30 additions & 15 deletions src/renderer/src/routes/downloads/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DropdownMenuTrigger
} from "@/components/ui/dropdown-menu";
import { Progress } from "@/components/ui/progress";
import { cn } from "@/lib/utils";
import type { DownloadRecord, DownloadState } from "~/types/downloads";
import {
CheckCircle2,
Expand Down Expand Up @@ -140,14 +141,15 @@ function isActive(state: DownloadState): boolean {

function DownloadItem({
record,
invalidate
invalidate,
fileMissing
}: {
record: DownloadRecord;
invalidate: () => void;
fileMissing: boolean;
}) {
const filename = filenameFromRecord(record);
const progress =
record.totalBytes > 0 ? Math.round((record.receivedBytes / record.totalBytes) * 100) : 0;
const progress = record.totalBytes > 0 ? Math.round((record.receivedBytes / record.totalBytes) * 100) : 0;

const handlePause = async () => {
const ok = await flow.downloads.pause(record.id);
Expand Down Expand Up @@ -197,14 +199,17 @@ function DownloadItem({

<div className="min-w-0 flex-1 space-y-1">
<div className="flex items-center gap-2">
<span className="text-sm text-foreground truncate block leading-snug font-medium">
<span
className={cn(
"text-sm text-foreground truncate block leading-snug font-medium",
fileMissing && "line-through text-muted-foreground"
)}
>
{filename}
</span>
</div>

{isActive(record.state) && record.totalBytes > 0 && (
<Progress value={progress} className="h-1.5" />
)}
{isActive(record.state) && record.totalBytes > 0 && <Progress value={progress} className="h-1.5" />}

<div className="flex items-center gap-2 text-[11px] text-muted-foreground">
<StateIcon state={record.state} />
Expand All @@ -219,9 +224,7 @@ function DownloadItem({
</>
)}
<span className="opacity-40">-</span>
<time dateTime={new Date(record.startTime).toISOString()}>
{formatTime(record.startTime)}
</time>
<time dateTime={new Date(record.startTime).toISOString()}>{formatTime(record.startTime)}</time>
</div>
</div>

Expand Down Expand Up @@ -336,6 +339,8 @@ function DownloadsPage() {
return () => window.clearTimeout(t);
}, [search]);

const [fileExistence, setFileExistence] = useState<Record<string, boolean>>({});

const { data, isError, isPending, refetch } = useQuery({
queryKey: ["downloads"],
queryFn: () => flow.downloads.list(),
Expand All @@ -346,6 +351,14 @@ function DownloadsPage() {
if (isError) toast.error("Could not load downloads");
}, [isError]);

// Check file existence for non-active downloads that have a savePath
useEffect(() => {
if (!data) return;
const idsToCheck = data.filter((dl) => !isActive(dl.state) && dl.savePath).map((dl) => dl.id);
if (idsToCheck.length === 0) return;
void flow.downloads.checkFilesExist(idsToCheck).then(setFileExistence);
}, [data]);

const filtered = useMemo(() => {
if (!data) return [];
if (!debouncedSearch) return data;
Expand All @@ -358,10 +371,7 @@ function DownloadsPage() {

const grouped = useMemo(() => groupByDay(filtered), [filtered]);

const hasActiveDownloads = useMemo(
() => data?.some((dl) => isActive(dl.state)) ?? false,
[data]
);
const hasActiveDownloads = useMemo(() => data?.some((dl) => isActive(dl.state)) ?? false, [data]);

const invalidate = () => {
void queryClient.invalidateQueries({ queryKey: ["downloads"] });
Expand Down Expand Up @@ -455,7 +465,12 @@ function DownloadsPage() {
<CardContent className="p-1">
<ul>
{group.items.map((dl) => (
<DownloadItem key={dl.id} record={dl} invalidate={invalidate} />
<DownloadItem
key={dl.id}
record={dl}
invalidate={invalidate}
fileMissing={dl.id in fileExistence && !fileExistence[dl.id]}
/>
))}
</ul>
</CardContent>
Expand Down
1 change: 1 addition & 0 deletions src/shared/flow/interfaces/browser/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface FlowDownloadsAPI {
openFile: (downloadId: string) => Promise<boolean>;
removeRecord: (downloadId: string) => Promise<boolean>;
clearCompleted: () => Promise<void>;
checkFilesExist: (downloadIds: string[]) => Promise<Record<string, boolean>>;
}