mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
e737190f54
* remove platform related code in sys.ts * remove browserType for minigame
73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
Object.assign(cc.sys, {
|
|
__init () {
|
|
this.isNative = false;
|
|
this.isBrowser = false;
|
|
this.isMobile = true;
|
|
this.language = jsb.language.substr(0, 2);
|
|
this.languageCode = jsb.language.toLowerCase();
|
|
var system = jsb.system.toLowerCase();
|
|
var platform = jsb.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 = jsb.width;
|
|
var h = jsb.height;
|
|
var ratio = jsb.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;
|
|
},
|
|
}); |