mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
5d5a8fc245
* add cocos runtime update update * support link-sure * update jsb * support oppo * move fs-utils && AudioPlayer to common update * fix loadSubPackage * support qtt * add huawei & vivo * remove qgame-adapter.js * optimize accelerometer * add back copyright
77 lines
2.2 KiB
JavaScript
77 lines
2.2 KiB
JavaScript
Object.assign(cc.sys, {
|
|
__init () {
|
|
this.isNative = false;
|
|
this.isBrowser = false;
|
|
this.isMobile = true;
|
|
|
|
let sysInfo = jsb.getSystemInfoSync();
|
|
// TODO: remove __getCurrentLanguage call
|
|
let language = sysInfo.language || (__getCurrentLanguage && __getCurrentLanguage());
|
|
this.language = language.substr(0, 2);
|
|
this.languageCode = language.toLowerCase();
|
|
var system = sysInfo.system.toLowerCase();
|
|
var platform = sysInfo.platform.toLowerCase();
|
|
|
|
if (platform === "android") {
|
|
this.os = this.OS_ANDROID;
|
|
}
|
|
else if (platform === "ios") {
|
|
this.os = this.OS_IOS;
|
|
}
|
|
|
|
// Adaptation to Android P
|
|
if (system === 'android p') {
|
|
system = 'android p 9.0';
|
|
}
|
|
|
|
var version = /[\d\.]+/.exec(system);
|
|
this.osVersion = version ? version[0] : system;
|
|
this.osMainVersion = parseInt(this.osVersion);
|
|
|
|
this.browserType = null;
|
|
this.browserVersion = null;
|
|
|
|
var w = sysInfo.screenWidth;
|
|
var h = sysInfo.screenHeight;
|
|
var ratio = sysInfo.pixelRatio || 1;
|
|
this.windowPixelResolution = {
|
|
width: ratio * w,
|
|
height: ratio * h
|
|
};
|
|
|
|
this.localStorage = window.localStorage;
|
|
|
|
var _supportWebp = false;
|
|
try {
|
|
var _canvas = document.createElement("canvas");
|
|
_supportWebp = _canvas.toDataURL('image/webp').startsWith('data:image/webp');
|
|
}
|
|
catch (err) { }
|
|
|
|
this.capabilities = {
|
|
canvas: true,
|
|
opengl: true,
|
|
webp: _supportWebp,
|
|
imageBitmap: false,
|
|
touches: true,
|
|
mouse: false,
|
|
keyboard: false,
|
|
accelerometer: true,
|
|
};
|
|
this.__audioSupport = {
|
|
ONLY_ONE: false,
|
|
WEB_AUDIO: false,
|
|
DELAY_CREATE_CTX: false,
|
|
format: ['.mp3']
|
|
};
|
|
},
|
|
|
|
openURL (url) {
|
|
jsb.openURL(url);
|
|
},
|
|
|
|
getBatteryLevel () {
|
|
const batteryInfo = jsb.getBatteryInfoSync();
|
|
return batteryInfo && batteryInfo.level;
|
|
},
|
|
}); |