convert mih web app from JS to WASm
This commit is contained in:
parent
eb213b01b6
commit
f9c71b656e
17 changed files with 78 additions and 127 deletions
|
|
@ -30,46 +30,32 @@
|
|||
|
||||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
|
||||
|
||||
<!-- Splash screen -->
|
||||
|
||||
|
||||
<!-- <script src="install_pwa.js" defer=""></script> -->
|
||||
<!-- Capture PWA install prompt event -->
|
||||
<script>
|
||||
let deferredPrompt;
|
||||
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
e.preventDefault(); // Prevent standard browser prompt banner
|
||||
deferredPrompt = e;
|
||||
});
|
||||
|
||||
function promptInstall() {
|
||||
deferredPrompt.prompt();
|
||||
}
|
||||
|
||||
// Listen for app install event
|
||||
window.addEventListener('appinstalled', () => {
|
||||
deferredPrompt = null;
|
||||
appInstalled();
|
||||
});
|
||||
|
||||
// Track how PWA was launched (either from browser or as PWA)
|
||||
function getLaunchMode() {
|
||||
const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
|
||||
if (deferredPrompt) hasPrompt();
|
||||
if (document.referrer.startsWith('android-app://')) {
|
||||
appLaunchedAsTWA();
|
||||
} else if (navigator.standalone || isStandalone) {
|
||||
appLaunchedAsPWA();
|
||||
if (deferredPrompt) {
|
||||
deferredPrompt.prompt();
|
||||
deferredPrompt.userChoice.then((choiceResult) => {
|
||||
if (choiceResult.outcome === 'accepted') {
|
||||
console.log('User accepted the PWA install prompt');
|
||||
}
|
||||
deferredPrompt = null;
|
||||
});
|
||||
} else {
|
||||
window.appLaunchedInBrowser();
|
||||
console.log('PWA installation prompt is not available yet.');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<!-- Splash screen -->
|
||||
<!-- <script>
|
||||
var dartPdfJsBaseUrl = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/";
|
||||
</script> -->
|
||||
<!--------------------->
|
||||
|
||||
// Helper to safely check from Dart if prompt is ready
|
||||
function isInstallPromptAvailable() {
|
||||
return deferredPrompt !== undefined && deferredPrompt !== null;
|
||||
} </script>
|
||||
|
||||
|
||||
<script type="application/ld+json">
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
let deferredPrompt;
|
||||
|
||||
// add to homescreen
|
||||
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;
|
||||
});
|
||||
|
||||
function isDeferredNotNull() {
|
||||
return deferredPrompt != null;
|
||||
}
|
||||
|
||||
function presentAddToHome() {
|
||||
if (deferredPrompt != null) {
|
||||
// Update UI to notify the user they can add to home screen
|
||||
// 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;
|
||||
});
|
||||
} else {
|
||||
console.log("deferredPrompt is null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue