Skip to content
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

feat: handle download links #840

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/app/applyDownloadNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export function applyDownloadNotification(browserWindow) {
notification.on('click', () => {
shell.showItemInFolder(pathToFile)
})
} else {
} else if (state === 'interrupted') {
notification = new Notification({
title: 'Download Failed',
body: `Something went wrong with the download of '${base}'.`,
})
}

notification.show()
notification?.show()
})
})
}
1 change: 0 additions & 1 deletion src/app/externalLinkHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function isExternalLink(url) {
* @return {{action: 'deny'} | {action: 'allow', outlivesOpener?: boolean, overrideBrowserWindowOptions?: import('electron').BrowserWindowConstructorOptions}}
*/
function windowOpenExternalLinkHandler(details, browserWindowOptions = {}) {
// TODO: Should handle different types of details.disposition? I.e. save-to-disk?
if (isExternalLink(details.url)) {
shell.openExternal(details.url)
return { action: 'deny' }
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ app.whenReady().then(async () => {
isInWindowRelaunch = false
})

ipcMain.on('app:downloadURL', (event, url) => mainWindow.webContents.downloadURL(url))

// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
app.on('activate', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ const TALK_DESKTOP = {
* @return {Promise<void>}
*/
setAppConfig: (key, value) => ipcRenderer.invoke('app:config:set', key, value),
/**
* Trigger download of a URL
* @param {string} url - URL to download
*/
downloadURL: (url) => ipcRenderer.send('app:downloadURL', url),
/**
* Send appData to main process on restore
*
Expand Down
14 changes: 14 additions & 0 deletions src/shared/setupWebPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ function applyHeaderHeight() {
document.documentElement.style.setProperty('--header-height', `${TITLE_BAR_HEIGHT}px`, 'important')
}

/**
* Handle download links
*/
function applyDownloadLinkHandler() {
document.addEventListener('click', (event) => {
const link = event.target.closest('a')
if (link && link.hasAttribute('download')) {
event.preventDefault()
window.TALK_DESKTOP.downloadURL(link.href)
}
})
}

/**
* Make all required initial setup for the web page for authorized user: server-rendered data, globals and ect.
*/
Expand All @@ -214,4 +227,5 @@ export async function setupWebPage() {
applyHeaderHeight()
applyAxiosInterceptors()
await applyL10n()
applyDownloadLinkHandler()
}