0

I'm having a Electron application internally I'm loading the Angular application. I'm downloading a byte array (i.e., ArrayBuffer) through an API call and passing those data to a method which I'm connecting through electron.remote.require('./file-service') to create a file in a local file system.

If I'm downloading till 120 MB it supports. if I'm downloading more than this size, it hangs the window and UI too became white screen.

Sample Angular Code:

declare var electron: any;
const { createDataFile } = electron.remote.require('./file-service')

const payLoad = new FormData();
const httpOptions =  {
      headers: new HttpHeaders(),
      reportProgress: true,
    };

const req = new HttpRequest('GET', 'http://localhost:8080/getData', payLoad, {...httpOptions, responseType: 'arraybuffer'});
this.http.request<ArrayBuffer>(req).subscribe((event: HttpEvent<ArrayBuffer>) => {

    switch (event.type) {
        case HttpEventType.Response:
            createDataFile(event.body)
        break;
    }

});

File System related code: file-service.js

module.exports = {
    createDataFile(fileData) {

    }
}

I made the method with zero statement, still its hanging and the window becomes white.

Electron window:

enter image description here

enter image description here

Kindly assist me how to fix this issue.

B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130

1 Answers1

0

https://github.com/electron/electron/blob/master/docs/api/remote.md#remote-objects

Each object (including functions) returned by the remote module represents an object in the main process (we call it a remote object or remote function). When you invoke methods of a remote object, call a remote function, or create a new object with the remote constructor (function), you are actually sending synchronous inter-process messages.

Electron's remote does synchronously serialize your data, so sending extremely large bytesize naturally causes whole ui goes unresponsive. even async IPC doesn't sounds feasible in this case (i.e 120MB is too large enough) - you need to redesign logic to store file without involving heavy IPC / serialization. That may not be only reason of your issue, but regardless should be changed.

OJ Kwon
  • 4,385
  • 1
  • 20
  • 24