-
Notifications
You must be signed in to change notification settings - Fork 9
/
is.js
160 lines (157 loc) · 4.75 KB
/
is.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Project: electron-is
* Version: 3.0.0
* Author: delvedor
* Twitter: @delvedor
* License: MIT
* GitHub: https://github.com/delvedor/electron-is
*/
'use strict'
const semver = require('semver')
const gt = semver.gt
const lt = semver.lt
const release = require('os').release
const isDev = require('electron-is-dev')
module.exports = {
// Checks if we are in renderer process
renderer: function () {
return process.type === 'renderer'
},
// Checks if we are in main process
main: function () {
return process.type === 'browser'
},
// Checks if we are under Mac OS
osx: function () {
return process.platform === 'darwin'
},
// Checks if we are under Mac OS
macOS: function () {
return this.osx()
},
// Checks if we are under Windows OS
windows: function () {
return process.platform === 'win32'
},
// Checks if we are under Linux OS
linux: function () {
return process.platform === 'linux'
},
// Checks if we are the processor's arch is x86
x86: function () {
return process.arch === 'ia32'
},
// Checks if we are the processor's arch is x64
x64: function () {
return process.arch === 'x64'
},
// Checks if the env is setted to 'production'
production: function () {
return !isDev
},
// Checks if the env is setted to 'dev'
dev: function () {
return isDev
},
// Checks if the app is running in a sandbox on macOS
sandbox: function () {
return 'APP_SANDBOX_CONTAINER_ID' in process.env
},
// Checks if the app is running as a Mac App Store build
mas: function () {
return process.mas === true
},
// Checks if the app is running as a Windows Store (appx) build
windowsStore: function () {
return process.windowsStore === true
},
// checks if all the 'is functions' passed as arguments are true
all: function () {
const isFunctions = new Array(arguments.length)
for (var i = 0; i < isFunctions.length; i++) {
isFunctions[i] = arguments[i]
}
if (!isFunctions.length) return
for (i = 0; i < isFunctions.length; i++) {
if (!isFunctions[i]()) return false
}
return true
},
// checks if all the 'is functions' passed as arguments are false
none: function () {
const isFunctions = new Array(arguments.length)
for (var i = 0; i < isFunctions.length; i++) {
isFunctions[i] = arguments[i]
}
if (!isFunctions.length) return
for (i = 0; i < isFunctions.length; i++) {
if (isFunctions[i]()) return false
}
return true
},
// returns true if one of the 'is functions' passed as argument is true
one: function () {
const isFunctions = new Array(arguments.length)
for (var i = 0; i < isFunctions.length; i++) {
isFunctions[i] = arguments[i]
}
if (!isFunctions.length) return
for (i = 0; i < isFunctions.length; i++) {
if (isFunctions[i]()) return true
}
return false
},
// checks the if the given release is the same of the OS
release: function (requested) {
if (this.osx()) {
return requested === osxRelease()
} else if (this.windows()) {
requested = requested.split('.')
const actual = release().split('.')
if (requested.length === 2) {
return `${actual[0]}.${actual[1]}` === `${requested[0]}.${requested[1]}`
}
return `${actual[0]}.${actual[1]}.${actual[2]}` === `${requested[0]}.${requested[1]}.${requested[2]}`
} else {
// Not implemented for Linux yet
return null
}
},
// checks if the given release is greater than the current OS release
gtRelease: function (requested) {
if (this.osx()) {
return gt(requested, osxRelease())
} else if (this.windows()) {
requested = requested.split('.')
const actual = release().split('.')
if (requested.length === 2) {
return gt(`${requested[0]}.${requested[1]}.0`, `${actual[0]}.${actual[1]}.0`)
}
return gt(`${requested[0]}.${requested[1]}.${requested[2]}`, `${actual[0]}.${actual[1]}.${actual[2]}`)
} else {
// Not implemented for Linux yet
return null
}
},
// checks if the given release is less than the current OS release
ltRelease: function (requested) {
if (this.osx()) {
return lt(requested, osxRelease())
} else if (this.windows()) {
requested = requested.split('.')
const actual = release().split('.')
if (requested.length === 2) {
return lt(`${requested[0]}.${requested[1]}.0`, `${actual[0]}.${actual[1]}.0`)
}
return lt(`${requested[0]}.${requested[1]}.${requested[2]}`, `${actual[0]}.${actual[1]}.${actual[2]}`)
} else {
// Not implemented for Linux yet
return null
}
}
}
// returns the current osx release
function osxRelease () {
const actual = release().split('.')
return `10.${actual[0] - 4}.${actual[1]}`
}