Skip to content

Commit

Permalink
Use Window Controls Overlay to hide the title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
TechAurelian committed Jun 29, 2024
1 parent fc63419 commit 4f8361f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
6 changes: 4 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
</head>

<body>
<!-- We need some content for the Lighthouse audit to pass. It's black on black, so it's invisible. -->
<p>The Simplest Progressive Web App Ever?</p>

<!-- Because we are using the Window Controls Overlay feature, we need to add a "title bar" div to enable dragging the window -->
<div class="empty-title-bar">
</div>

<script type="module" src="/scripts/app.js"></script>

Expand Down
1 change: 1 addition & 0 deletions public/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "The simplest Progressive Web App ever? It's just a black window / screen, but it can be used to test PWA support on any browser and platform. Other uses?",
"dir": "ltr",
"display": "standalone",
"display_override": ["window-controls-overlay"],
"icons": [
{
"src": "/images/icons/blackpwa-app-icon-192.png",
Expand Down
8 changes: 0 additions & 8 deletions public/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
// When running as standalone (PWA), clear the document title using an invisible (zero-width) control character
function clearTitle(mql) {
if (mql.matches) document.title = '\u200E';
}

const mql = window.matchMedia('(display-mode: standalone)');
clearTitle(mql);
mql.addEventListener('change', (e) => clearTitle(e));
12 changes: 12 additions & 0 deletions public/styles/app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
body {
background: black;
color: black;
}

/* The "title bar" div that is used to drag the window around. */
.empty-title-bar {
position: fixed;
-webkit-app-region: drag;
app-region: drag;

left: env(titlebar-area-x, 0);
top: env(titlebar-area-y, 0);
width: env(titlebar-area-width, 100%);
height: env(titlebar-area-height, 33px);
}
2 changes: 1 addition & 1 deletion public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

const curCacheVersion = "0";
const curCacheVersion = "1";
const curCacheName = `blackpwa-${curCacheVersion}`;
const urlsToCache = [
'/',
Expand Down

0 comments on commit 4f8361f

Please sign in to comment.