@idlebox/common 1.3.20 → 1.3.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +1,58 @@
1
1
  declare const process: any;
2
2
  declare const navigator: any;
3
+ declare const window: any;
4
+ declare const global: any;
3
5
 
4
- let _isWindows = false;
5
- let _isMacintosh = false;
6
- let _isLinux = false;
7
- let _isNative = false;
8
- let _isWeb = false;
9
- let _userAgent: string;
6
+ export const hasProcess = typeof process !== 'undefined' && typeof process.pid === 'number';
7
+ export const hasWindow = typeof window !== 'undefined' && globalThis === window;
8
+ export const hasGlobal = typeof global !== 'undefined' && globalThis === global;
10
9
 
11
- export const isElectron =
12
- typeof process !== 'undefined' &&
13
- typeof process.versions !== 'undefined' &&
14
- typeof process.versions.electron !== 'undefined';
15
- export const isElectronRenderer = isElectron && process.type === 'renderer';
16
- export const isElectronMain = !isElectronRenderer;
17
-
18
- if (typeof navigator === 'object' && !isElectronRenderer) {
19
- _userAgent = navigator.userAgent;
20
- _isWindows = _userAgent.indexOf('Windows') >= 0;
21
- _isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
22
- _isLinux = _userAgent.indexOf('Linux') >= 0;
23
- _isWeb = true;
24
- } else if (typeof process === 'object') {
25
- _userAgent = `nodejs(${process.versions.node})`;
26
- if (process.versions.electron) {
27
- _userAgent += ` electron(${process.versions.electron})`;
28
- if (isElectronRenderer) {
29
- _userAgent += ' ' + navigator.userAgent;
10
+ export let isElectron = false,
11
+ isElectronSandbox = false,
12
+ isElectronRenderer = false,
13
+ isElectronMain = false;
14
+ if (hasProcess) {
15
+ if (typeof process.versions?.electron !== 'undefined') {
16
+ isElectron = true;
17
+ if (process.type === 'renderer') {
18
+ isElectronRenderer = true;
19
+ } else {
20
+ isElectronMain = true;
30
21
  }
31
22
  }
32
- _isWindows = process.platform === 'win32';
33
- _isMacintosh = process.platform === 'darwin';
34
- _isLinux = process.platform === 'linux';
35
- _isNative = true;
36
- } else {
37
- _userAgent = 'unsupported';
23
+ } else if (hasWindow) {
24
+ if (window.navigator.userAgent.includes(' Electron/')) {
25
+ isElectron = true;
26
+ isElectronRenderer = true;
27
+ isElectronSandbox = true;
28
+ }
29
+ }
30
+
31
+ export let isWindows = false;
32
+ export let isMacintosh = false;
33
+ export let isLinux = false;
34
+ export let isNative = false;
35
+ export let isWeb = false;
36
+ export let is64Bit = false;
37
+
38
+ if (hasWindow && !hasProcess) {
39
+ const userAgent = navigator.userAgent;
40
+ isWindows = userAgent.includes('Windows NT');
41
+ isMacintosh = userAgent.includes('Macintosh');
42
+ isLinux = userAgent.includes('Linux');
43
+ isWeb = true;
44
+ is64Bit = userAgent.includes('x64');
45
+ } else if (hasProcess) {
46
+ isNative = true;
47
+ is64Bit = process.arch === 'x64';
48
+ if (process.platform === 'linux') {
49
+ isLinux = true;
50
+ } else if (process.platform === 'darwin') {
51
+ isMacintosh = true;
52
+ } else if (process.platform === 'win32') {
53
+ isWindows = true;
54
+ }
38
55
  }
39
56
 
40
- export const isWindows = _isWindows;
41
- export const isMacintosh = _isMacintosh;
42
- export const isLinux = _isLinux;
43
- export const isNative = _isNative;
44
- export const isWeb = _isWeb;
45
- export const userAgent = _userAgent;
46
57
  export const sepList = isWindows ? ';' : ':';
58
+ export const is32Bit = !is64Bit;