GithubHelp home page GithubHelp logo

Comments (10)

sKY02644 avatar sKY02644 commented on May 20, 2024 3

Any solution to this please?

Facing the same issue

from electron-dl.

corwin-of-amber avatar corwin-of-amber commented on May 20, 2024

@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:

Uncaught Exception:
TypeError: Cannot read properties of null (reading 'getOwnerBrowserWindow')
at Function.n.fromWebContents (node:electron/js2c/browser_init:33:1573)
at Session.listener (/Users/corwin/var/workspace/Teaching.Web.GR/node_modules/electron-dl/index.js:68:64)
at Session.emit (node:events:406:35)

The exception is not caught by my try .. catch because apparently it occurs in a tasklet.

from electron-dl.

Kiyozz avatar Kiyozz commented on May 20, 2024

@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:

Uncaught Exception:
TypeError: Cannot read properties of null (reading 'getOwnerBrowserWindow')
at Function.n.fromWebContents (node:electron/js2c/browser_init:33:1573)
at Session.listener (/Users/corwin/var/workspace/Teaching.Web.GR/node_modules/electron-dl/index.js:68:64)
at Session.emit (node:events:406:35)

The exception is not caught by my try .. catch because apparently it occurs in a tasklet.

const win is for sure null. That is why you get this error.

from electron-dl.

corwin-of-amber avatar corwin-of-amber commented on May 20, 2024

Thanks for the reply. But that's exactly what the docs say:
https://github.com/sindresorhus/electron-dl#use-it-manually

Which also worked with a previous version of Electron, and this is why I attached my excerpt to this issue.
Why would BrowserWindow.getFocusedWindow return null?

I went ahead and printed it. It is not null.

from electron-dl.

Kiyozz avatar Kiyozz commented on May 20, 2024

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

from electron-dl.

corwin-of-amber avatar corwin-of-amber commented on May 20, 2024

@Kiyozz thanks, but what is this.win in your case? Is this code part of a class definition (since you are using this)?

from electron-dl.

Kiyozz avatar Kiyozz commented on May 20, 2024

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 initialize.

await initialize(win)

In initialize, I create the instance and I inject it.

const downloadManager = new DownloadManager(
    httpManager,
    modDownloadStore,
    win,
    sendIpcEvents,
  )

from electron-dl.

corwin-of-amber avatar corwin-of-amber commented on May 20, 2024

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?)

from electron-dl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.