您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

utils.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.setAttribute('aria-hidden', 'true');
  31. img.onload = function() {
  32. resolve(true);
  33. };
  34. img.onerror = function() {
  35. resolve(false);
  36. };
  37. });
  38. const extensionInstalledFunction = info => isExtensionInstalled(info);
  39. return Promise.all(
  40. (config.chromeExtensionsInfo || []).map(info => extensionInstalledFunction(info))
  41. );
  42. }