-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
113 lines (98 loc) · 2.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
(function (window, factory) {
if (typeof exports === 'object') {
module.exports = factory();
} else {
window.platform = factory();
}
})(this, function () {
let platform = {};
/**
* @property isNode
* @type boolean
*
* Indicates whether executes in node.js application.
*/
platform.isNode = !!(typeof process !== 'undefined' && process.versions && process.versions.node);
if (platform.isNode) {
/**
* @property isDarwin
* @type boolean
*
* Indicates whether executes in OSX.
*/
platform.isDarwin = process.platform === 'darwin';
/**
* @property isWin32
* @type boolean
*
* Indicates whether executes in Windows.
*/
platform.isWin32 = process.platform === 'win32';
/**
* @property isElectron
* @type boolean
*
* Indicates whether executes in electron.
*/
platform.isElectron = !!('electron' in process.versions);
} else {
// http://stackoverflow.com/questions/19877924/what-is-the-list-of-possible-values-for-navigator-platform-as-of-today
let platform_ = window.navigator.platform;
platform.isDarwin = platform_.substring(0, 3) === 'Mac';
platform.isWin32 = platform_.substring(0, 3) === 'Win';
platform.isElectron = window.navigator.userAgent.indexOf('Electron') !== -1;
}
/**
* @property isNative
* @type boolean
*
* Indicates whether executes in native environment (compare to web-browser).
*/
platform.isNative = platform.isElectron;
/**
* @property isPureWeb
* @type boolean
*
* Indicates whether executes in common web browser.
*/
platform.isPureWeb = !platform.isNode && !platform.isNative;
/**
* @property isRendererProcess
* @type boolean
*
* Indicates whether executes in common web browser, or editor's renderer process(web-page).
*/
platform.isRendererProcess = typeof process === 'undefined' || process.type === 'renderer';
/**
* @property isMainProcess
* @type boolean
*
* Indicates whether executes in editor's main process.
*/
platform.isMainProcess = typeof process !== 'undefined' && process.type === 'browser';
/**
* @property isDev
* @type boolean
*
* Check if Electron is running in development.
* If we are in renderer process and `nodeIntegration` is false, isDev will be undefined.
*/
// NOTE: Reference from https://github.com/sindresorhus/electron-is-dev
if ( typeof process !== 'undefined' ) {
platform.isDev = process.defaultApp || /[\\/]electron-prebuilt[\\/]/.test(process.execPath) || /[\\/]electron[\\/]/.test(process.execPath);
}
/**
* @property isRetina
* @type boolean
*
* Check if running in retina display.
*/
Object.defineProperty(platform, 'isRetina', {
enumerable: true,
get () {
return platform.isRendererProcess && window.devicePixelRatio && window.devicePixelRatio > 1;
}
});
return platform;
});