Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed May 21, 2018
1 parent 26251a6 commit 0074ac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions pwacompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@
function process(manifest, href) {
const icons = manifest['icons'] || [];
icons.sort((a, b) => parseInt(b.sizes, 10) - parseInt(a.sizes, 10)); // largest first
icons.forEach((icon) => {
const appleTouchIcons = icons.map((icon) => {
const attr = {'rel': 'icon', 'href': new URL(icon['src'], href), 'sizes': icon['sizes']};
push('link', attr);

if (isSafari) {
attr['rel'] = 'apple-touch-icon';
const node = push('link', attr);
icon['node'] = node;
return push('link', attr);
}
});

Expand All @@ -97,6 +95,7 @@
const backgroundIsLight =
shouldUseLightForeground(manifest['background_color'] || defaultSplashColor);
const themeIsLight = shouldUseLightForeground(manifest['theme_color'] || 'black');
const title = manifest['name'] || manifest['short_name'] || document.title;

// Add related iTunes app from manifest.
const itunes = findAppleId(manifest['related_applications']);
Expand All @@ -105,6 +104,7 @@
// nb. Safari 11.3+ gives a deprecation warning about this meta tag.
meta('apple-mobile-web-app-status-bar-style', themeIsLight ? 'default' : 'black');
meta('apple-mobile-web-app-capable', isCapable);
meta('apple-mobile-web-app-title', title);

function splashFor({width, height}, orientation, icon) {
const ratio = window.devicePixelRatio;
Expand All @@ -117,7 +117,6 @@

ctx.font = `${defaultSplashTextSize}px HelveticaNeue-CondensedBold`;
ctx.fillStyle = backgroundIsLight ? 'white' : 'black';
const title = manifest['name'] || manifest['short_name'] || document.title;
const textWidth = ctx.measureText(title).width;

if (icon) {
Expand Down Expand Up @@ -160,39 +159,39 @@
previous.add(portrait);
previous.add(landscape);
}
updateSplash();
updateSplash(null);

// fetch the largest icon to generate a splash screen
if (!icons.length) {
if (!appleTouchIcons.length) {
return;
}
const icon = icons[0];
const icon = appleTouchIcons[0];
const img = new Image();
img.onload = () => {
updateSplash(img);

// also redraw icon
// also check and redraw icon
if (!manifest['background_color']) {
return;
}
const redrawn = updateTransparent(img, manifest['background_color']);
if (redrawn === null) {
return; // the rest probably aren't interesting either
}
icon['node'].href = redrawn;
icon.href = redrawn;

// fetch and fix all others
icons.slice(1).forEach((icon) => {
// fetch and fix all remaining icons
appleTouchIcons.slice(1).forEach((icon) => {
const img = new Image();
img.onload = () => {
const redrawn = updateTransparent(img, manifest['background_color'], true);
icon['node'].href = redrawn;
icon.href = redrawn;
};
img.src = icon['node'].href;
img.src = icon.href;
});

};
img.src = icon['node'].href;
img.src = icon.href;
}

function findAppleId(related) {
Expand Down Expand Up @@ -233,6 +232,7 @@
context.drawImage(image, 0, 0);

// look for transparent pixel in top-left
// TODO: Chrome actually checks the four corners for some cases.
if (!force) {
const imageData = context.getImageData(0, 0, 1, 1);
if (imageData.data[3] == 255) {
Expand Down
14 changes: 7 additions & 7 deletions pwacompat.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0074ac8

Please sign in to comment.