Source: lib/os.js

'use strict';

/* 系统检测 */
/** @module os */

import * as utils from './utils';

/**
 * @member {Boolean} plus - 是否是钱香app端网页
 */
let plus;
/**
 * @member {Boolean} ios - 是否是ios平台
 */
let ios;
/**
 * @member {Boolean} iphone - 是否是iphone平台
 */
let iphone;
/**
 * @member {Boolean} ipad - 是否是ipad平台
 */
let ipad;
/**
 * @member {Boolean} android - 是否是android平台
 */
let android;
/**
 * @member {String} version - 平台版本
 */
let version;
/**
 * @member {Boolean} isBadAndroid - 是否是安卓4.4一下的浏览的环境
 */
let isBadAndroid;
/**
 * @member {Boolean} wechat - 是否是微信环境
 */
let wechat;

(function () {
    if (!utils.isBrowserEnv()) {
        return;
    }
    let ua = navigator.userAgent.toLowerCase();
    // wechat
    // eslint-disable-next-line
    let wechatMatch = ua.match(/(micromessenger)\/([\d\.]+)/i);
    if (wechatMatch) { //wechat
        wechat = {
            version: wechatMatch[2].replace(/_/g, '.')
        };
    }
    // android
    // eslint-disable-next-line
    let androidMatch = ua.match(/(android);?[\s\/]+([\d.]+)?/);
    if (androidMatch) {
        android = true;
        version = androidMatch[2];
        isBadAndroid = !(/chrome\/\d/.test(window.navigator.appVersion.toLowerCase()));
    }
    // iphone
    // eslint-disable-next-line
    let iphoneMatch = ua.match(/(iphone\sos)\s([\d_]+)/);
    if (iphoneMatch) { //iphone
        ios = iphone = true;
        version = iphoneMatch[2].replace(/_/g, '.');
    } else {
        // eslint-disable-next-line
        let ipadMatch = ua.match(/(ipad).*os\s([\d_]+)/);
        if (ipadMatch) { // ipad
            ios = ipad = true;
            version = ipadMatch[2].replace(/_/g, '.');
        }
    }

    // qianxiang app
    if (window['getQxAppInfo']) {
        if (utils.isNativeFunction(window['getQxAppInfo'])) {
            plus = true;
        }
    } else if (window.QxApi && window.QxApi['getQxAppInfo']) {
        if (utils.isNativeFunction(window.QxApi['getQxAppInfo'])) {
            plus = true;
        }
    }
})();

export {
    plus,
    ios,
    iphone,
    ipad,
    android,
    version,
    isBadAndroid,
    wechat
};