Skip to content

Commit

Permalink
feature(env): 扩展对小程序运行环境的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
IronL committed Dec 12, 2019
1 parent 27a1cb2 commit 273f8c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ Painter.prototype = {
ctx.restore();
}

if (env.wxa) {
// Flush for weixin application
if (env.mpa) {
// Flush for miniprogram application
util.each(this._layers, function (layer) {
if (layer && layer.ctx && layer.ctx.draw) {
layer.ctx.draw();
Expand Down
17 changes: 15 additions & 2 deletions src/core/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
*/

/* global wx */
/* global my */
/* global tt */

var env = {};

if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
if (isMiniProgramEnv()) {
// In Weixin Application
env = {
browser: {},
os: {},
node: false,
wxa: true, // Weixin Application
mpa: true, // miniprogram Application
canvasSupported: true,
svgSupported: false,
touchEventsSupported: true,
Expand Down Expand Up @@ -159,6 +161,17 @@ function detect(ua) {
};
}

/**
* Detect is in miniprogram environment
*/
function isMiniProgramEnv() {
return (
(typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function')
|| (typeof my === 'object' && typeof my.getSystemInfoSync === 'function')
|| (typeof tt === 'object' && typeof tt.getSystemInfoSync === 'function')
);
}

// See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
// function detectPassiveSupport() {
// // Test via a getter in the options object to see if the passive property is accessed
Expand Down

0 comments on commit 273f8c0

Please sign in to comment.