Git Product home page Git Product logo

Comments (5)

WellMafra avatar WellMafra commented on July 19, 2024

@salehmosleh any news?

from electron-dl.

salehmosleh avatar salehmosleh commented on July 19, 2024

@WellMafra , we have to run electron-dl codes on Main side (main.js), if you need run it on render side , use ipcMain/IPCRenderer to send request to Main side.

const {app, BrowserWindow, ipcMain} = require('electron');
const {download} = require('electron-dl');

ipcMain.on('download-btn', (e, args) => {
	download(BrowserWindow.getFocusedWindow(), args.url)
		.then(dl => console.log(dl.getSavePath()))
		.catch(console.error);
});

also i want to use electron-download-manager , it is better for me.

from electron-dl.

pedrobertao avatar pedrobertao commented on July 19, 2024

Any news on how to solve this ? @salehmosleh

from electron-dl.

salehmosleh avatar salehmosleh commented on July 19, 2024

@pedrobertao , i explain it on the above.

from electron-dl.

chrispavlopoulos avatar chrispavlopoulos commented on July 19, 2024

Just to clarify for anyone in the future: you CAN NOT use electron-dl functions from your preload script. You must declare the download function in your main file and communicate between main.js and preload.js by using ipcMain and ipcRenderer.

This is what worked for me:

// main.js
const electronDl = require('electron-dl');
electronDl();

app.on('ready', () => {
    ipcMain.on('electron-dl-download', async (event, { url }) => {
      const win = BrowserWindow.getFocusedWindow();
        try {
            console.log(await electronDl.download(win, url));
        } catch (error) {
            if (error instanceof electronDl.CancelError) {
              console.info('item.cancel() was called');
        } else {
          console.error(error);
        }
      }
    });
});


// preload.js
const { ipcRenderer } = require('electron');

window.download = (args) => {
  ipcRenderer.send("electron-dl-download", args);
};

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.