googleapis / googleapis/google-api-nodejs-client

This client needs proper integration with Electron really badly

Aperta
#2,714 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
type: feature request web
Lingua principale
TypeScript
Stelle
12.3k
Fork
2k
Merge medio
1g 9h
PR unite (30g)
24

Descrizione

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()`](https://github.com/googleapis/nodejs-googleapis-common/blob/master/src/isbrowser.ts) is implemented.

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

```js
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()`](https://github.com/googleapis/nodejs-googleapis-common/blob/98edc86818868aaedd291268b79347298d84b95f/src/isbrowser.ts#L14) like this:

```js
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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da googleapis-common/src/isbrowser.ts, quindi traccia il modo in cui le opzioni di gaxios raggiungono il client durante l'esempio di upload di Drive. Verifica come funziona attualmente il rilevamento del renderer di Electron e determina in che modo fetchImplementation o un'opzione dell'ambiente dovrebbero influenzarlo; il lavoro è completato quando gli upload funzionano in Electron senza il workaround IPC segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
electron, node.js, typescript
Ambito
api, desktop
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.