DEV: Add if a user is using an Apple device in widget capabilities (#15021)

* Consolidate device capability sniffing in caps
This commit is contained in:
Natalie Tay 2021-11-23 11:21:31 +08:00 committed by GitHub
parent 49c49e8ae0
commit 340901c913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -478,9 +478,9 @@ export function inCodeBlock(text, pos) {
}
export function translateModKey(string) {
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
// Mac users are used to glyphs for shortcut keys
if (mac) {
const { isApple } = helperContext().capabilities;
// Apple device users are used to glyphs for shortcut keys
if (isApple) {
string = string
.replace("Shift", "\u21E7")
.replace("Meta", "\u2318")

View File

@ -1,4 +1,9 @@
// Initializes an object that lets us know about browser's capabilities
const APPLE_NAVIGATOR_PLATFORMS = /iPhone|iPod|iPad|Macintosh|MacIntel/;
const APPLE_USERAGENTDATA_PLATFORM = /macOS/;
export default {
name: "sniff-capabilities",
@ -28,6 +33,11 @@ export default {
(/iPhone|iPod/.test(navigator.userAgent) || caps.isIpadOS) &&
!window.MSStream;
caps.isApple =
APPLE_NAVIGATOR_PLATFORMS.test(navigator.platform) ||
(navigator.userAgentData &&
APPLE_USERAGENTDATA_PLATFORM.test(navigator.userAgentData.platform));
caps.hasContactPicker =
"contacts" in navigator && "ContactsManager" in window;
caps.canVibrate = "vibrate" in navigator;