diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-08-03 00:01:33 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-08-02 20:01:33 -0800 |
commit | 1de3bd3b4340cb51b2699a14a92d653db988a988 (patch) | |
tree | 604703f9acf4ea3b71f30bdfa532020e9fb233be /webapp/utils | |
parent | 790dd91e7d93b5debaf86915c34f8a73a3ff95bd (diff) | |
download | chat-1de3bd3b4340cb51b2699a14a92d653db988a988.tar.gz chat-1de3bd3b4340cb51b2699a14a92d653db988a988.tar.bz2 chat-1de3bd3b4340cb51b2699a14a92d653db988a988.zip |
PLT-3640 Add mobile landing pages (#3674)
* PLT-3640 Moved all clientside user agent snooping into a single file
* PLT-3640 Added mobile landing pages on login to iOS and Android web apps
* PLT-3640 Moved landing page to appear before first login
* PLT-3640 Fixed detection of Chrome on Android
* PLT-3640 Disabled mobile landing pages when their respective URLs are set to blank
Diffstat (limited to 'webapp/utils')
-rw-r--r-- | webapp/utils/user_agent.jsx | 86 | ||||
-rw-r--r-- | webapp/utils/utils.jsx | 51 |
2 files changed, 90 insertions, 47 deletions
diff --git a/webapp/utils/user_agent.jsx b/webapp/utils/user_agent.jsx new file mode 100644 index 000000000..657718627 --- /dev/null +++ b/webapp/utils/user_agent.jsx @@ -0,0 +1,86 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +/* +Example User Agents +-------------------- + +Chrome: + Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 + +Firefox: + Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0 + +IE11: + Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko + +Edge: + Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586 + +Desktop App: + Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Mattermost/1.2.1 Chrome/49.0.2623.75 Electron/0.37.8 Safari/537.36 + Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586 + +Android Chrome: + Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 + +Android App: + Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 + Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 + Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36 + +iOS Safari: + Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3 + +iOS Android: + Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3 + +iOS App: + Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69 +*/ + +const userAgent = window.navigator.userAgent; + +export function isChrome() { + return userAgent.indexOf('Chrome') > -1; +} + +export function isSafari() { + return userAgent.indexOf('Safari') !== -1 && userAgent.indexOf('Chrome') === -1; +} + +export function isIosSafari() { + return userAgent.indexOf('iPhone') !== -1 && userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('CriOS') === -1; +} + +export function isIosChrome() { + return userAgent.indexOf('CriOS') !== -1; +} + +export function isIosWeb() { + return isIosSafari() || isIosChrome(); +} + +export function isAndroidChrome() { + return userAgent.indexOf('Android') !== -1 && userAgent.indexOf('Chrome') !== -1 && userAgent.indexOf('Version') === -1; +} + +export function isAndroidWeb() { + return isAndroidChrome(); +} + +export function isMobileApp() { + return userAgent.indexOf('iPhone') !== -1 && userAgent.indexOf('Safari') === -1 && userAgent.indexOf('CriOS') === -1; +} + +export function isFirefox() { + return userAgent.indexOf('Firefox') !== -1; +} + +export function isInternetExplorer() { + return userAgent.indexOf('Trident') !== -1; +} + +export function isEdge() { + return userAgent.indexOf('Edge') !== -1; +}
\ No newline at end of file diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index 4b3c8518c..187c7d7f4 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -12,6 +12,7 @@ import Constants from 'utils/constants.jsx'; var ActionTypes = Constants.ActionTypes; import * as AsyncClient from './async_client.jsx'; import Client from 'client/web_client.jsx'; +import * as UserAgent from 'utils/user_agent.jsx'; import {browserHistory} from 'react-router/es6'; import {FormattedMessage} from 'react-intl'; @@ -43,31 +44,6 @@ export function cmdOrCtrlPressed(e) { return (isMac() && e.metaKey) || (!isMac() && e.ctrlKey); } -export function isChrome() { - if (navigator.userAgent.indexOf('Chrome') > -1) { - return true; - } - return false; -} - -export function isSafari() { - if (navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) { - return true; - } - return false; -} - -export function isIosChrome() { - // https://developer.chrome.com/multidevice/user-agent - return navigator.userAgent.indexOf('CriOS') !== -1; -} - -export function isMobileApp() { - const userAgent = navigator.userAgent; - - return userAgent.indexOf('iPhone') !== -1 && userAgent.indexOf('Safari') === -1 && userAgent.indexOf('CriOS') === -1; -} - export function isInRole(roles, inRole) { var parts = roles.split(' '); for (var i = 0; i < parts.length; i++) { @@ -146,7 +122,7 @@ export function notifyMe(title, body, channel, teamId) { var canDing = true; export function ding() { - if (!isBrowserFirefox() && canDing) { + if (!UserAgent.isFirefox() && canDing) { var audio = new Audio(bing); audio.play(); canDing = false; @@ -751,7 +727,7 @@ export function updateCodeTheme(userTheme) { xmlHTTP.open('GET', cssPath, true); xmlHTTP.onload = function onLoad() { $link.attr('href', cssPath); - if (isBrowserFirefox()) { + if (UserAgent.isFirefox()) { $link.one('load', () => { changeCss('code.hljs', 'visibility: visible'); }); @@ -1048,25 +1024,6 @@ export function generateId() { return id; } -export function isBrowserFirefox() { - return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1; -} - -// Checks if browser is IE10 or IE11 -export function isBrowserIE() { - if (window.navigator && window.navigator.userAgent) { - var ua = window.navigator.userAgent; - - return ua.indexOf('Trident/7.0') > 0 || ua.indexOf('Trident/6.0') > 0; - } - - return false; -} - -export function isBrowserEdge() { - return window.navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('edge') > -1; -} - export function getDirectChannelName(id, otherId) { let handle; @@ -1244,7 +1201,7 @@ export function fillArray(value, length) { // Checks if a data transfer contains files not text, folders, etc.. // Slightly modified from http://stackoverflow.com/questions/6848043/how-do-i-detect-a-file-is-being-dragged-rather-than-a-draggable-element-on-my-pa export function isFileTransfer(files) { - if (isBrowserIE() || isBrowserEdge()) { + if (UserAgent.isInternetExplorer() || UserAgent.isEdge()) { return files.types != null && files.types.contains('Files'); } |