Skip to content

Commit

Permalink
feat+refactor(ui/Platform): explicitly specify all boolean props (the…
Browse files Browse the repository at this point in the history
…y were previously undefined if "false") #17482
  • Loading branch information
rstoenescu committed Sep 17, 2024
1 parent 87dfaa4 commit 2481bab
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 95 deletions.
31 changes: 18 additions & 13 deletions ui/src/plugins/platform/Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,40 @@ function getPlatform (UA) {
const matched = getMatch(userAgent, platformMatch)
const browser = {
mobile: false,
desktop: false,

cordova: false,
capacitor: false,
nativeMobile: false,
// nativeMobileWrapper: void 0,
electron: false,
desktop: false,
bex: false,
android: false,
blackberry: false,
cros: false,
ios: false,
ipad: false,
iphone: false,
ipod: false,
kindle: false,

linux: false,
mac: false,
win: false,
winphone: false,
playbook: false,
silk: false,
cros: false,

chrome: false,
firefox: false,
opera: false,
safari: false,
vivaldi: false,
edge: false,
edgeChromium: false,
ie: false,
webkit: false
webkit: false,

android: false,
ios: false,
ipad: false,
iphone: false,
ipod: false,
kindle: false,
winphone: false,
blackberry: false,
playbook: false,
silk: false
}

if (matched.browser) {
Expand Down
121 changes: 52 additions & 69 deletions ui/src/plugins/platform/Platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,25 @@
"desc": "Major browser version as a number"
},

"desktop": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is desktop"
},
"mobile": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is mobile"
},
"electron": {
"desktop": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is Electron"
"desc": "Whether the platform is desktop"
},
"bex": {

"cordova": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is BEX(Browser Extension)"
"desc": "Whether the platform is Cordova"
},
"capacitor": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is Capacitor"
},
"cordova": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is Cordova"
},
"nativeMobile": {
"type": "Boolean",
"required": false,
"desc": "Whether the platform is a native mobile wrapper"
},
"nativeMobileWrapper": {
Expand All @@ -79,110 +65,107 @@
"values": [ "'cordova'", "'capacitor'" ],
"desc": "Type of the native mobile wrapper"
},

"webkit": {
"electron": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is a Webkit one"
"desc": "Whether the platform is Electron"
},
"bex": {
"type": "Boolean",
"desc": "Whether the platform is BEX(Browser Extension)"
},

"chrome": {
"linux": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Google Chrome"
"desc": "Whether the operating system is Linux"
},
"firefox": {
"mac": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Firefox"
"desc": "Whether the operating system is Mac OS"
},
"safari": {
"win": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Safari"
"desc": "Whether the operating system is Windows"
},
"edgeChromium": {
"cros": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Microsoft Edge (Chromium)"
"desc": "Whether the operating system is Chrome OS"
},
"edge": {

"chrome": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Microsoft Edge Legacy"
"desc": "Whether the browser is Google Chrome"
},
"firefox": {
"type": "Boolean",
"desc": "Whether the browser is Firefox"
},
"opera": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Opera"
},
"safari": {
"type": "Boolean",
"desc": "Whether the browser is Safari"
},
"vivaldi": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Vivaldi"
},

"win": {
"edge": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is Windows"
"desc": "Whether the browser is Microsoft Edge Legacy"
},
"linux": {
"edgeChromium": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is Linux"
"desc": "Whether the browser is Microsoft Edge (Chromium)"
},
"mac": {
"ie": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is Mac OS"
"desc": "Whether the browser is Internet Explorer"
},
"cros": {
"webkit": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is Chrome OS"
"desc": "Whether the browser is a Webkit or Webkit-based one"
},

"android": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is Android"
},
"ios": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is iOS"
},
"winphone": {
"ipad": {
"type": "Boolean",
"required": false,
"desc": "Whether the operating system is Windows Phone"
"desc": "Whether the device is an iPad"
},

"iphone": {
"type": "Boolean",
"required": false,
"desc": "Whether the device is an iPhone"
},
"ipad": {
"type": "Boolean",
"required": false,
"desc": "Whether the device is an iPad"
},
"ipod": {
"type": "Boolean",
"required": false,
"desc": "Whether the device is an iPod"
},

"kindle": {
"type": "Boolean",
"required": false,
"desc": "Whether the device is a Kindle"
},
"winphone": {
"type": "Boolean",
"desc": "Whether the operating system is Windows Phone"
},
"blackberry": {
"type": "Boolean",
"desc": "Whether the device is a Blackberry"
},
"playbook": {
"type": "Boolean",
"desc": "Whether the device is a Blackberry Playbook"
},
"silk": {
"type": "Boolean",
"required": false,
"desc": "Whether the browser is Amazon Silk"
}
},
Expand Down
31 changes: 18 additions & 13 deletions ui/src/plugins/platform/Platform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe('[Platform API]', () => {
versionNumber: expect.any(Number),

mobile: expect.any(Boolean),
desktop: expect.any(Boolean),

cordova: expect.any(Boolean),
capacitor: expect.any(Boolean),
nativeMobile: expect.any(Boolean),
Expand All @@ -45,30 +47,33 @@ describe('[Platform API]', () => {
'capacitor'
]),
electron: expect.any(Boolean),
desktop: expect.any(Boolean),
bex: expect.any(Boolean),
android: expect.any(Boolean),
blackberry: expect.any(Boolean),
cros: expect.any(Boolean),
ios: expect.any(Boolean),
ipad: expect.any(Boolean),
iphone: expect.any(Boolean),
ipod: expect.any(Boolean),
kindle: expect.any(Boolean),

linux: expect.any(Boolean),
mac: expect.any(Boolean),
win: expect.any(Boolean),
winphone: expect.any(Boolean),
playbook: expect.any(Boolean),
silk: expect.any(Boolean),
cros: expect.any(Boolean),

chrome: expect.any(Boolean),
firefox: expect.any(Boolean),
opera: expect.any(Boolean),
safari: expect.any(Boolean),
vivaldi: expect.any(Boolean),
edge: expect.any(Boolean),
edgeChromium: expect.any(Boolean),
ie: expect.any(Boolean),
webkit: expect.any(Boolean)
webkit: expect.any(Boolean),

android: expect.any(Boolean),
ios: expect.any(Boolean),
ipad: expect.any(Boolean),
iphone: expect.any(Boolean),
ipod: expect.any(Boolean),
kindle: expect.any(Boolean),
winphone: expect.any(Boolean),
blackberry: expect.any(Boolean),
playbook: expect.any(Boolean),
silk: expect.any(Boolean)
}

const actualKeys = Object.keys(Platform.is)
Expand Down

0 comments on commit 2481bab

Please sign in to comment.