-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.html
340 lines (220 loc) · 9.58 KB
/
install.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Install Website (PWA)</title>
<meta name="description" content="Install website as app (PWA). The site or page will look and run like an app and will be among other installed programs.">
<meta name="keywords" content="
install, download, website, PWA, WebApp, app, page, main,
">
<link rel="alternate" type="application/rss+xml" title="Website RSS" href="/rss.xml">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<!--<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">-->
<link rel="icon" sizes="512x512" href="/img/logo.png" type="image/png">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<!-- main -->
<link rel="preload" href="./js/main.js" as="script">
<link rel="preload" href="./css/main.css" as="style">
<link rel="stylesheet" href="./css/main.css" type="text/css">
<link rel="preload" href="./css/auto.css" as="style">
<link rel="stylesheet" type="text/css" href="./css/auto.css" id="theme">
<link rel="preload" href="./css/style.css" as="style">
<link rel="stylesheet" href="./css/style.css" type="text/css">
<noscript>
<link rel="stylesheet" type="text/css" href="./css/noscript.css">
</noscript>
<!-- // main -->
</head>
<body>
<!-- Nav v.1.2.2 -->
<!-- page, style.css, main.js, noscript.css -->
<!-- nav HTML part -->
<header>
<div class="wrapper3 navTop">
<div class="margin"></div>
<nav>
<a class="countMenuItem inlineBlock padding" style="padding-left: 0;" href="./index.html" title="nav1"><img class="logo2 reduceLight" src="./img/logo.png" alt="logo" style="max-width: 26px;"></a>
<div class="menuTop">
<!-- menu items -->
<a class="countMenuItem brand borderBottomTransparent inlineBlock padding" href="./main-list.html">Main</a>
<a class="countMenuItem brand borderBottomTransparent inlineBlock padding" href="./projects-page.html">Projects</a>
<a class="countMenuItem brand borderBottomTransparent inlineBlock padding" href="./games-list.html">Games</a>
<!-- // menu items -->
</div>
<!-- // menuTop -->
<!-- dropdown menu -->
<!-- https://www.w3schools.com/howto/howto_js_dropdown.asp -->
<div id="dropdownMenuCSS"><!-- CSS menu if js off -->
<button onclick="dropdownMenuFunction();" class="brand inlineBlock padding" id="dropdownMenuButton">☰ Menu</button>
<div id="dropdownMenu" class="dropdownMenuContent shadow bg2 padding2 borderRadius2">
<div class="dropdownMenuWrapper">
<!--<div class="padding2">menu name</div>-->
<div class="dropdownMenuContentColumn">
<!-- menu items dublicate -->
<a class="countMenuItem brand borderBottomTransparent inlineBlock padding" href="./main-list.html">Main</a>
<a class="countMenuItem brand borderBottomTransparent inlineBlock padding" href="./projects-page.html">Projects</a>
<a class="countMenuItem brand borderBottomTransparent inlineBlock padding" href="./games-list.html">Games</a>
<!-- // menu items dublicate -->
</div>
</div>
</div>
</div>
<!--<hr />-->
<!-- // dropdown menu -->
<span class="countMenuItem"></span>
<span class="countMenuItem"></span>
<span class="countMenuItem"></span>
<a class="countMenuItem inlineBlock padding mClassNavUp brand" style="margin-right: var(--padding);" href="../" title="../Up">List (↑)</a>
<form class="noscriptHide inlineBlock padding" style="padding-right: 0;" method="GET" action="./site-search.html" role="search">
<!--<label for="siteSearch" class="xSmall op">search:</label>-->
<input id="siteSearch" type="search" placeholder="site search" name="q" autocomplete="off">
</form>
</nav>
</div>
</header>
<!-- // nav -->
<!--<hr>-->
<!-- content -->
<main class="contentCenter">
<div class="wrapperL">
<h1 class="tCenter op padding2 insertIconTitle">Install Website (PWA)</h1>
<div class="block tCenter small">(PWA v.1.2.2024.08.26)</div>
<div class="block padding2 margin2"></div>
<div><b class="red">!Note:</b> Before installing, hide file extensions in <a class="inlineBlock padding brand bold" href="/settings.html#confHideLinkExt">Settings</a> to fix 404 error.</div>
<div class="block padding3 margin3"></div>
<div class="wrapperL tCenter">
<button class="post padding2 margin2 borderList" onclick="startInstallPWA()"><span class="bold">Start Install (14,82 MB) - 1 first step</span>
<span class="small block padding2">registration sw.js (service worker) and adding files to the cache.</span></button>
<div id="startInstallStatus" class="post padding2 margin2 borderList"></div>
<button class="add-button post padding2 margin2 borderList bold green" onclick="startInstallPWA()">Install (14,82 MB) - 2. second step</button>
<div class="block padding2 margin2"></div>
<button class="post padding2 margin2 borderList" onclick="startUnregisterSW()">Unregister SW (serviceWorker)</button>
<div id="unregisterStatus" class="post padding2 margin2 borderList"></div>
<div class="block padding3 margin3"></div>
</div>
<script>
// v.1.0.1
// reg worker
function startUnregisterSW(){
//confirm("Are you sure?"); // true, false
//https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/unregister
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/sw.js", { scope: "/" })
.then((registration) => {
// registration worked
console.log("Registration succeeded.");
document.getElementById("unregisterStatus").innerHTML = "Registration succeeded.";
registration.unregister().then((boolean) => {
// if boolean = true, unregister is successful
if(boolean == true){
document.getElementById("unregisterStatus").innerHTML = `unregister is successful ` + boolean;
console.log(`unregister is successful ` + boolean);
}else{
document.getElementById("unregisterStatus").innerHTML = `unregister status: ` + boolean;
console.log(`unregister status: ` + boolean);
}
});
})
.catch((error) => {
// registration failed
console.error(`Registration failed with ` + error);
document.getElementById("unregisterStatus").innerHTML = `Registration for unregister failed with error: ` + error;
});
}
}
// insert manifest in header
let element = document.createElement('link');
element.setAttribute('rel', 'manifest');
element.setAttribute('href', "/manifest.webmanifest");
//element.crossOrigin = 'anonymous';
element.crossOrigin = 'use-credentials';
document.querySelector('head').appendChild(element);
function startInstallPWA(){
//https://github.com/mdn/pwa-examples
// Register service worker to control making site work offline
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.js', { scope: "/"} )
.then((registration) => {
console.log('Service Worker Registered');
document.getElementById("startInstallStatus").innerHTML = `Service Worker Registered`;
registration.addEventListener("updatefound", () => {
// If updatefound is fired, it means that there's
// a new service worker being installed.
const installingWorker = registration.installing;
console.log(
"A new service worker is being installed:",
installingWorker,
);
document.getElementById("startInstallStatus").innerHTML = `A new service worker is being installed: installingWorker`;
// You can listen for changes to the installing service worker's
// state via installingWorker.onstatechange
});
/*//message to worker
//https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/message_event
navigator.serviceWorker.addEventListener("message", (event) => {
// event is a MessageEvent object
console.log(`The service worker sent me a message: ` + event.data);
});
navigator.serviceWorker.ready.then((registration) => {
registration.active.postMessage('Hi serviceWorker!');
});*/
})
.catch((error) => {
// registration failed
console.error(`Registration failed with` + error);
document.getElementById("startInstallStatus").innerHTML = `Registration failed with` + error;
});
async function registerPeriodicSync() {
const swRegistration = await navigator.serviceWorker.ready;
swRegistration.periodicSync.register("update", {
// try to update every 24 hours
minInterval: 24 * 60 * 60 * 1000,
});
}
}
}
//https://stackoverflow.com/questions/58985103/progressive-web-app-not-showing-install-button-in-browser-bar
// Code to handle install prompt on desktop
let deferredPrompt;
const addBtn = document.querySelector('.add-button');
addBtn.style.display = 'none';
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI to notify the user they can add to home screen
addBtn.style.display = 'block';
addBtn.addEventListener('click', () => {
// hide our user interface that shows our A2HS button
addBtn.style.display = 'none';
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
deferredPrompt = null;
});
});
});
</script>
<div class="padding2 margin2 block tCenter op light border small">
<div class="">
Generated using a PHP function: website dir to PWA in <a class="blue" href="/other-projects">/other-projects</a>
</div>
</div>
</div>
</main>
<!-- // content -->
<footer id="footer"></footer>
<script src="./js/main.js"></script>
<script src="./js/script.js"></script>
</body>
</html>