-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
how to use electron latest in electron-dl #136
Comments
@integemjack can you provide a description of the error? I am trying the following: ipcMain.on('download-request', async (event, {url}) => {
console.log('requesting to download', url);
try {
const win = BrowserWindow.getFocusedWindow();
await download(win, url);
}
catch (e) { console.error('(download)', e); }
}); and I'm getting this popup:
The exception is not caught by my |
|
Thanks for the reply. But that's exactly what the docs say: Which also worked with a previous version of Electron, and this is why I attached my excerpt to this issue. I went ahead and printed it. It is not null. |
Any solution to this please? Facing the same issue |
I use latest electron-dl and Electron in my project. No issue so far. Sample code win is injected through function parameter, not with getFocusedWindow import dl from 'electron-dl'
void dl.download(this.win, mod.url, {
filename: mod.name,
onStarted: item => {
modToUse = this.updateDownloadInStore(modToUse, {
localFilePath: item.getSavePath(),
})
this.addDownloadInStore(modToUse, item)
this.setPreviousTime(modToUse)
this.startInterval(mod.id)
resolve(modToUse)
},
onProgress: () => {
this.sendIpcEvents.progressModDownload(this.modDownloadStore.get())
},
onCompleted: () => {
modToUse = this.updateDownloadInStore(modToUse, {
state: DownloadState.finish,
downloadedSize: mod.size,
})
this.sendIpcEvents.finishModDownload(this.modDownloadStore.get())
this.deletePreviousTime(modToUse)
},
})
}) this.win: BrowserWindow
mod.url: string |
@Kiyozz thanks, but what is this.win in your case? Is this code part of a class definition (since you are using |
Class method startDownloadOfMod(mod: BaseModDownload): Promise<BaseModDownload> {
// ...
return new Promise<BaseModDownload>(resolve => {
void dl.download(this.win, mod.url, {
filename: mod.name,
onStarted: item => {
modToUse = this.updateDownloadInStore(modToUse, {
localFilePath: item.getSavePath(),
})
this.addDownloadInStore(modToUse, item)
this.setPreviousTime(modToUse)
this.startInterval(mod.id)
resolve(modToUse)
},
})
})
} Class constructor constructor(
private http: HttpManager,
private modDownloadStore: ModDownloadStore,
private win: BrowserWindow,
private sendIpcEvents: SendIpcEvents,
) {} So in my main file, I create the window. I use a function I called await initialize(win) In const downloadManager = new DownloadManager(
httpManager,
modDownloadStore,
win,
sendIpcEvents,
) |
Can anyone try this with their code base? (I kind of stopped using electron-dl in my code as a result of this issue; @OfekA-IAI, @sKY02644, perhaps?) |
You can use : instead of BrowserWindow.getFocusedWindow() to retrieve the root window |
I encountered the same issue. It turned out to be the url passed to download function. I was passing the url without the origin (https://hostname). I was passing in just the path (/path/to/file/to/download) without the origin. I Later changed to pass in the full url (https://hostname:port/part/to/file/to/download. This is what worked for me |
No description provided.
The text was updated successfully, but these errors were encountered: