Call renderer process from React-Redux action (Ele

2019-05-29 02:10发布

I have a electron application which uses React & Redux, so I have action creators, reducers etc.

I also have a function in my renderer file (nodejs) which does some async stuff.

I want to call this function from within my action creator. I guess I will have to use redux-thunk for this or some other async library, however, I am not quite sure how to access this function in the renderer process and use it in my react.redux app?

So e.g. for the action creator:

export const downloadFromYoutube = (download) => {
//I want to call the function here
};

and my renderer file only contains this one function which does async stuff:

var YoutubeMp3Downloader = require('youtube-mp3-downloader');

function downloadFromYoutube() {
  console.log("Hello");
  //Configure YoutubeMp3Downloader with y our settings
  var YD = new YoutubeMp3Downloader({
      "ffmpegPath": "/usr/local/Cellar/ffmpeg/3.2.2/bin/ffmpeg",        // Where is the FFmpeg binary located?
      "outputPath": "/Users/dominik/Coding/youtube-downloader-papa/downloads/",    // Where should the downloaded and encoded files be stored?
      "youtubeVideoQuality": "highest",       // What video quality should be used?
      "queueParallelism": 2,                  // How many parallel downloads/encodes should be started?
      "progressTimeout": 2000                 // How long should be the interval of the progress reports
  });
  console.log("Downloading");
  //Download video and save as MP3 file
  YD.download("jhjPSj-qnyg");


  YD.on("finished", function(data) {
      console.log(data);
  });

  YD.on("error", function(error) {
      console.log(error);
  });

  YD.on("progress", function(progress) {
      console.log(progress);
  });
}


    }

0条回答
登录 后发表回答