feat: support image lightbox viewer and file download (#151)
* feat: add lightbox overlay with nice mechanics * ui tweak for top bar in stream view * support locally downloading attachments
This commit was merged in pull request #151.
This commit is contained in:
@@ -454,6 +454,28 @@ ipcMain.handle('link:open-external', async (_event, url: string) => {
|
||||
await shell.openExternal(url);
|
||||
});
|
||||
|
||||
// --- Attachment download ---
|
||||
// Triggers a native download with save-as dialog. Cross-origin safe — unlike
|
||||
// the web `<a download>` hack, which is ignored for cross-origin URLs.
|
||||
ipcMain.on(
|
||||
'attachment:download',
|
||||
(event, payload: { url: string; filename?: string }) => {
|
||||
const win = BrowserWindow.fromWebContents(event.sender);
|
||||
if (!win) return;
|
||||
const { url, filename } = payload ?? {};
|
||||
if (typeof url !== 'string') return;
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) return;
|
||||
|
||||
const dlSession = win.webContents.session;
|
||||
const onWillDownload = (_e: Electron.Event, item: Electron.DownloadItem) => {
|
||||
if (filename) item.setSaveDialogOptions({ defaultPath: filename });
|
||||
dlSession.removeListener('will-download', onWillDownload);
|
||||
};
|
||||
dlSession.on('will-download', onWillDownload);
|
||||
win.webContents.downloadURL(url);
|
||||
},
|
||||
);
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
|
||||
Reference in New Issue
Block a user