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.js 1.2KB

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