google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

This client needs proper integration with Electron really badly

Open m4heshd opened this issue 4 years ago • 0 comments

First of all, This client is a massive time saver for the developers and really grateful for the time and energy you all have put into this. Second of all, I'm not even close to an expert on any of these things. I just recently started using this client. I've already been through previously tracked issues (#1878, #1083, #2085) that's related to my issues. I'm opening this new feature request since @JustinBeckwith advised me to do so and I'd like to share my suggestions.

Is your feature request related to a problem? Please describe. Currently there's no way to practically use this client for uploading tasks in Electron renderer and from what I'm seeing, it's for no good reason. As you all may know, Electron's renderer process is fully capable of using Node.js APIs, so the client shouldn't behave in a different way in that context. I'm fully behind the idea of added support for the browser but in my opinion it should be a choice for the developer and shouldn't cost existing good functionality. I've seen the suggestion of IPC everywhere but any Electron dev with the slightest experience knows that's hardly a solution. I personally have succeeded in avoiding usage of IPC almost 99% of the time even in fairly massive applications.

When you boil this issue down to a gist, all this trouble just because how isBrowser() is implemented.

Describe the solution you'd like The client should respect the fetchImplementation property set in gaxios options.

const nodeFetch = require('node-fetch/lib/index').default;

drive.files.create({
            requestBody: {...fileMetadata},
            media: media,
            fields: 'id'
        }, {
            fetchImplementation: nodeFetch, // `isBrowser()` function should respect this option
            /* Or something like this */
            environment: 'node' // or 'browser'
        })

Describe alternatives you've considered I've manually overridden isBrowser() like this:

function isBrowser() {
    if (process && process.type) return false;
    return typeof window !== 'undefined';
}

And voila. Everything works perfectly as intended.

At the end, now I'm using my own forks of googleapis-common and @googleapis/drive in my projects because from what I'm seeing, there's no other option.

m4heshd avatar Aug 14 '21 04:08 m4heshd