You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.ts 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Platform from '../react/Platform';
  2. /**
  3. * Returns whether or not the current environment is a mobile device.
  4. *
  5. * @returns {boolean}
  6. */
  7. export function isMobileBrowser() {
  8. return Platform.OS === 'android' || Platform.OS === 'ios';
  9. }
  10. /**
  11. * Returns whether or not the current environment is an ios mobile device.
  12. *
  13. * @returns {boolean}
  14. */
  15. export function isIosMobileBrowser() {
  16. return Platform.OS === 'ios';
  17. }
  18. /**
  19. * Checks whether the chrome extensions defined in the config file are installed or not.
  20. *
  21. * @param {Object} config - Objects containing info about the configured extensions.
  22. *
  23. * @returns {Promise[]}
  24. */
  25. export function checkChromeExtensionsInstalled(config: any = {}) {
  26. const isExtensionInstalled = (info: any) => new Promise(resolve => {
  27. const img = new Image();
  28. img.src = `chrome-extension://${info.id}/${info.path}`;
  29. img.setAttribute('aria-hidden', 'true');
  30. img.onload = function() {
  31. resolve(true);
  32. };
  33. img.onerror = function() {
  34. resolve(false);
  35. };
  36. });
  37. const extensionInstalledFunction = (info: any) => isExtensionInstalled(info);
  38. return Promise.all(
  39. (config.chromeExtensionsInfo || []).map((info: any) => extensionInstalledFunction(info))
  40. );
  41. }