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

utils.ts 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // @ts-ignore
  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: any = {}) {
  27. const isExtensionInstalled = (info: any) => 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: any) => isExtensionInstalled(info);
  39. return Promise.all(
  40. (config.chromeExtensionsInfo || []).map((info: any) => extensionInstalledFunction(info))
  41. );
  42. }