Skip to content

Commit 75bdb05

Browse files
Add Electron specific logic to isBrowser check
1 parent 24a2d91 commit 75bdb05

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

api/WebApi.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ import os = require('os');
4242
import url = require('url');
4343
import path = require('path');
4444

45-
const isBrowser: boolean = typeof window !== 'undefined';
45+
// https://www.electronjs.org/docs/api/process
46+
interface ElectronProcess {
47+
type: 'browser' | 'renderer' | 'worker'
48+
};
49+
const isElectron: boolean = process && process.versions && process.versions.hasOwnProperty('electron');
50+
const isElectronWebpage: boolean = isElectron && (<ElectronProcess><unknown>process).type === 'renderer';
51+
const isBrowser: boolean = typeof window !== 'undefined' && (!isElectron || isElectronWebpage);
52+
4653
/**
4754
* Methods to return handler objects (see handlers folder)
4855
*/

0 commit comments

Comments
 (0)