get-device.js 586 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {
  2. getSupport
  3. } from './get-support.js';
  4. let deviceCached;
  5. function calcDevice({
  6. userAgent
  7. } = {}) {
  8. const support = getSupport();
  9. const device = {
  10. ios: false,
  11. android: false
  12. };
  13. const res = uni.getSystemInfoSync();
  14. if (res.platform == "android") {
  15. device.os = 'android';
  16. device.android = true;
  17. }
  18. if (res.platform == "ios") {
  19. device.os = 'ios';
  20. device.ios = true;
  21. } // Export object
  22. return device;
  23. }
  24. function getDevice(overrides = {}) {
  25. if (!deviceCached) {
  26. deviceCached = calcDevice(overrides);
  27. }
  28. return deviceCached;
  29. }
  30. export {
  31. getDevice
  32. };