|
6 | 6 | <link rel="manifest" href="manifest.json" />
|
7 | 7 | <style>
|
8 | 8 | :root {
|
9 |
| - --header-height: 55px; |
| 9 | + --header-height: 39px; |
| 10 | + --header-padding: 8px; |
10 | 11 | }
|
11 | 12 |
|
12 | 13 | body {
|
|
19 | 20 | display: flex;
|
20 | 21 | justify-content: space-between;
|
21 | 22 | align-items: center;
|
22 |
| - padding: 8px; |
| 23 | + padding: var(--header-padding); |
23 | 24 | background-color: #1e2327;
|
24 | 25 | }
|
25 | 26 |
|
|
44 | 45 |
|
45 | 46 | #wp {
|
46 | 47 | width: 100%;
|
47 |
| - height: calc(100vh - var(--header-height)); |
| 48 | + height: calc(100vh - var(--header-height) - (2 * var(--header-padding))); |
48 | 49 | border: 0;
|
49 | 50 | }
|
50 | 51 |
|
|
74 | 75 | window.addEventListener("beforeinstallprompt", (event) => {
|
75 | 76 | event.preventDefault();
|
76 | 77 | installPrompt = event;
|
77 |
| - if (isInstallHeaderHidden()) { |
78 |
| - hideInstallHeader(); |
79 |
| - } else { |
80 |
| - showInstallHeader(); |
81 |
| - } |
| 78 | + showInstallHeader(); |
82 | 79 | });
|
83 | 80 | installButton.addEventListener("click", async () => {
|
84 | 81 | if (!installPrompt) {
|
|
89 | 86 | hideInstallHeader();
|
90 | 87 | });
|
91 | 88 | closeInstallButton.addEventListener("click", () => {
|
92 |
| - saveHideInstallHeader(); |
93 | 89 | hideInstallHeader();
|
94 | 90 | });
|
95 |
| - function saveHideInstallHeader() { |
96 |
| - localStorage.setItem("hideInstallHeader", "true"); |
97 |
| - } |
98 |
| - function isInstallHeaderHidden() { |
99 |
| - return localStorage.getItem("hideInstallHeader") === "true"; |
100 |
| - } |
101 | 91 | function hideInstallHeader() {
|
102 | 92 | document.body.classList.add("hide-install-header");
|
103 | 93 | }
|
|
107 | 97 |
|
108 | 98 | // Boot Playground
|
109 | 99 | import { startPlaygroundWeb } from "https://playground.wordpress.net/client/index.js";
|
| 100 | + const slug = "{{PWA_SLUG}}"; |
| 101 | + |
| 102 | + function isWordPressInstalled(slug) { |
| 103 | + return localStorage.getItem(`wordpress-installed-for-${slug}`) === 'true'; |
| 104 | + } |
| 105 | + function setWordPressInstalled(slug) { |
| 106 | + localStorage.setItem(`wordpress-installed-for-${slug}`, 'true'); |
| 107 | + } |
| 108 | + const shouldInstallWordPress = !isWordPressInstalled(slug); |
110 | 109 | const client = await startPlaygroundWeb({
|
111 | 110 | iframe: document.getElementById("wp"),
|
112 | 111 | remoteUrl: `https://playground.wordpress.net/remote.html`,
|
| 112 | + mounts: [ |
| 113 | + { |
| 114 | + mountpoint: '/wordpress', |
| 115 | + device: { |
| 116 | + type: 'opfs', |
| 117 | + path: `/pwa-sites/${slug}`, |
| 118 | + }, |
| 119 | + }, |
| 120 | + ], |
| 121 | + shouldInstallWordPress, |
113 | 122 | blueprint: {{BLUEPRINT}}
|
114 | 123 | });
|
115 | 124 | await client.isReady();
|
| 125 | + if (shouldInstallWordPress) { |
| 126 | + setWordPressInstalled(slug); |
| 127 | + } |
116 | 128 | </script>
|
117 | 129 | </body>
|
118 | 130 | </html>
|
0 commit comments