Skip to content

Commit

Permalink
minor Closure poking
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed May 6, 2020
1 parent cf0fc80 commit d393ec3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<link rel="manifest" href="./manifest.json" />
<meta name="theme-color" content="blue" />
<meta name="theme-color" content="red" />
<script src="../src/pwacompat.js"></script>
<script src="../pwacompat.min.js"></script>
</head>
<body>

Expand Down
26 changes: 12 additions & 14 deletions pwacompat.min.js

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

18 changes: 11 additions & 7 deletions src/pwacompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ function unused() {
* @return {?Element}
*/
function getElementInHead(selector) {
return document.head.querySelector(selector);
// It's possible to pass "bad" attr or values here (originally from the manifest); just
// return null if there's something wrong.
try {
return document.head.querySelector(selector);
} catch (e) {
return null;
}
}

/**
Expand All @@ -83,10 +89,6 @@ function unused() {
* @return {boolean}
*/
function isLinkPresent(attr, value) {
if (/["\\]/.test(value)) {
// This should practically never happen. Don't allow quotes or escapes here.
return false;
}
return Boolean(getElementInHead('link[' + attr + '="' + value + '"]'));
}

Expand Down Expand Up @@ -202,7 +204,7 @@ function unused() {
}
return parseInt(size, 10) || 0; // NaN is falsey
});
return Math.max(...sizes);
return Math.max.apply(null, sizes); // don't use ... as Closure inserts additional code
}

/**
Expand Down Expand Up @@ -516,7 +518,9 @@ function unused() {
if (!t) {
return; // something went wrong, we had a UWP without titleBar
}
t.foregroundColor = colorToWindowsRGBA(themeIsLight ? 'black' : 'white');
// Foreground is black if theme is light, otherwise white.
const v = themeIsLight ? 255 : 0;
t.foregroundColor = /** @type {WindowsColor} */ ({'r': v, 'g': v, 'b': v, 'a': 255});
t.backgroundColor = colorToWindowsRGBA(color);
}
}
Expand Down

0 comments on commit d393ec3

Please sign in to comment.