From 0e7e19c561b1f5cd02cebbfe104a5d52e0e6983a Mon Sep 17 00:00:00 2001 From: Sam Thorogood Date: Mon, 18 Jun 2018 11:28:32 +1000 Subject: [PATCH] QQ and UC meta --- pwacompat.js | 27 ++++++++++++++++++++++++++- pwacompat.min.js | 18 +++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/pwacompat.js b/pwacompat.js index 450a981..54a00b2 100644 --- a/pwacompat.js +++ b/pwacompat.js @@ -82,7 +82,8 @@ } }); - const isCapable = capableDisplayModes.indexOf(manifest['display']) !== -1; + const display = manifest['display']; + const isCapable = capableDisplayModes.indexOf(display) !== -1; meta('mobile-web-app-capable', isCapable); updateThemeColor(manifest['theme_color'] || 'black'); @@ -90,6 +91,19 @@ meta('msapplication-starturl', manifest['start_url'] || '/'); meta('msapplication-TileColor', manifest['theme_color']); } + + // TODO(samthor): We don't detect QQ or UC, we just set the vars anyway. + const orientation = simpleOrientationFor(manifest['orientation']); + meta('x5-orientation', orientation); // QQ + meta('screen-orientation', orientation); // UC + if (display === 'fullscreen') { + meta('x5-fullscreen', 'true'); // QQ + meta('full-screen', 'yes'); // UC + } else if (isCapable) { + meta('x5-page-mode', 'app'); // QQ + meta('browsermode', 'application'); // UC + } + if (!isSafari) { return; // the rest of this file is for Safari } @@ -211,6 +225,17 @@ return itunes; } + function simpleOrientationFor(v) { + v = String(v || ''); + const prefix = v.substr(0, 3); + if (prefix === 'por') { + return 'portrait'; + } else if (prefix === 'lan') { + return 'landscape'; + } + return ''; + } + /** * @param {string} color */ diff --git a/pwacompat.min.js b/pwacompat.min.js index 6ebf0b6..f36d137 100644 --- a/pwacompat.min.js +++ b/pwacompat.min.js @@ -1,9 +1,9 @@ -(function(){function n(){var a=document.head.querySelector('link[rel="manifest"]'),b=a?a.href:"";Promise.resolve().then(function(){if(!b)throw'can\'t find \'';var a={};"use-credentials"===b.crossOrigin&&(a.credentials="include");return window.fetch(b,a)}).then(function(a){return a.json()}).then(function(a){return z(a,b)}).catch(function(a){return console.warn("pwacompat.js error",a)})}function r(a,b){a=document.createElement(a);for(var c in b)a.setAttribute(c,b[c]); -document.head.appendChild(a);return a}function g(a,b){b&&(!0===b&&(b="yes"),r("meta",{name:a,content:b}))}function z(a,b){function c(b,c,f){var h=b.width,d=b.height,e=window.devicePixelRatio;b=t({width:h*e,height:d*e});b.scale(e,e);b.fillStyle=a.background_color||"#f8f9fa";b.fillRect(0,0,h,d);b.translate(h/2,(d-32)/2);b.font="24px HelveticaNeue-CondensedBold";b.fillStyle=n?"white":"black";h=b.measureText(u).width;f&&(d=f.width/e,e=f.height/e,128a?a/12.92:Math.pow((a+.055)/1.055,2.4)});return 3\'';var a={};"use-credentials"===b.crossOrigin&&(a.credentials="include");return window.fetch(b,a)}).then(function(a){return a.json()}).then(function(a){return A(a,b)}).catch(function(a){return console.warn("pwacompat.js error",a)})}function r(a,b){a=document.createElement(a);for(var d in b)a.setAttribute(d,b[d]); +document.head.appendChild(a);return a}function c(a,b){b&&(!0===b&&(b="yes"),r("meta",{name:a,content:b}))}function A(a,b){function d(b,d,f){var k=b.width,c=b.height,e=window.devicePixelRatio;b=t({width:k*e,height:c*e});b.scale(e,e);b.fillStyle=a.background_color||"#f8f9fa";b.fillRect(0,0,k,c);b.translate(k/2,(c-32)/2);b.font="24px HelveticaNeue-CondensedBold";b.fillStyle=q?"white":"black";k=b.measureText(u).width;f&&(c=f.width/e,e=f.height/e,128a?a/12.92:Math.pow((a+.055)/1.055,2.4)});return 3