初始化提交
This commit is contained in:
24
frontend/src/utils/pwa.js
Normal file
24
frontend/src/utils/pwa.js
Normal file
@@ -0,0 +1,24 @@
|
||||
let request;
|
||||
|
||||
let isInstallable = false;
|
||||
|
||||
// The file is not useful now.
|
||||
window.addEventListener('beforeinstallprompt', (r) => {
|
||||
console.log('beforeinstallprompt')
|
||||
// Prevent Chrome 67 and earlier from automatically showing the prompt
|
||||
r.preventDefault()
|
||||
request = r
|
||||
isInstallable = true;
|
||||
});
|
||||
|
||||
export async function installPWA() {
|
||||
if (request) {
|
||||
console.log('start install')
|
||||
let installResponse = await request.prompt();
|
||||
console.info({installResponse});
|
||||
return installResponse.outcome === 'accepted';
|
||||
} else {
|
||||
console.log('The request is not available');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user