desktop v0.1.20 + web: notify on download complete (was silent) (batch135)

Suppressing the save dialog made downloads completely silent — "nothing happened" even though
the file saved to Downloads. Now on download 'done': (1) tell the web UI → branded toast
"Saved X to your Downloads folder" when the window is focused; (2) native OS notification
(click → reveal in Explorer) when the app is minimized/in the tray, so it's never double-noticed;
(3) a failure notice. preload exposes onDownloadDone; home.html shows the toast.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-19 16:03:24 +05:30
parent 30eaf37773
commit f2b965bd3d
4 changed files with 25 additions and 2 deletions
+18
View File
@@ -465,6 +465,24 @@ function configureSession() {
let target = path.join(dir, name), n = 1;
while (fs.existsSync(target)) target = path.join(dir, `${base} (${n++})${ext}`);
item.setSavePath(target);
// Since we suppressed the save dialog, the download would otherwise be completely silent. Give feedback
// when it finishes: a notification (click → reveal the file in Explorer) so the user knows it saved and
// where. Also tell the web UI so it can show its own toast. On failure, say so.
item.once('done', (_ev, state) => {
try {
const ok = state === 'completed';
const savedName = ok ? path.basename(target) : (item.getFilename() || 'file');
// Always tell the web UI (it shows a branded toast when the window is up).
try { if (win && !win.isDestroyed()) win.webContents.send('download-done', { name: savedName, path: ok ? target : '', ok }); } catch (_) {}
// If the window is focused, that toast is enough — skip the native notification to avoid a double
// notice. If the app is minimized/in the tray, show a native notification instead (click → reveal).
const focused = win && !win.isDestroyed() && win.isVisible() && win.isFocused();
if (!focused && Notification.isSupported()) {
if (ok) { const note = new Notification({ title: 'Download complete', body: savedName + ' — saved to your Downloads folder. Click to show it.' }); note.on('click', () => { try { shell.showItemInFolder(target); } catch (_) {} }); note.show(); }
else new Notification({ title: 'Download failed', body: savedName + ' could not be saved.' }).show();
}
} catch (_) {}
});
} catch (_) {}
});
}