From 340901c913dc85ed054106b78d2b6dbed5e12240 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Tue, 23 Nov 2021 11:21:31 +0800 Subject: [PATCH] DEV: Add if a user is using an Apple device in widget capabilities (#15021) * Consolidate device capability sniffing in caps --- app/assets/javascripts/discourse/app/lib/utilities.js | 6 +++--- .../app/pre-initializers/sniff-capabilities.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.js index e075a40f81e..acdc69825e0 100644 --- a/app/assets/javascripts/discourse/app/lib/utilities.js +++ b/app/assets/javascripts/discourse/app/lib/utilities.js @@ -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") diff --git a/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js b/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js index 7567fa54474..acc9e14fa5c 100644 --- a/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js +++ b/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js @@ -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;