From 75bdb05f726484eaf14a9624e704578bc50b8d98 Mon Sep 17 00:00:00 2001 From: Matthew Williamson Date: Tue, 27 Apr 2021 09:45:31 -0700 Subject: [PATCH] Add Electron specific logic to isBrowser check --- api/WebApi.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/WebApi.ts b/api/WebApi.ts index 3f475a1..8f53731 100644 --- a/api/WebApi.ts +++ b/api/WebApi.ts @@ -42,7 +42,14 @@ import os = require('os'); import url = require('url'); import path = require('path'); -const isBrowser: boolean = typeof window !== 'undefined'; +// https://www.electronjs.org/docs/api/process +interface ElectronProcess { + type: 'browser' | 'renderer' | 'worker' +}; +const isElectron: boolean = process && process.versions && process.versions.hasOwnProperty('electron'); +const isElectronWebpage: boolean = isElectron && (process).type === 'renderer'; +const isBrowser: boolean = typeof window !== 'undefined' && (!isElectron || isElectronWebpage); + /** * Methods to return handler objects (see handlers folder) */