Browse Source

1.1.4

master
enne2 2 years ago
parent
commit
d5cbe55d81
  1. 45
      main.py

45
main.py

@ -114,7 +114,52 @@ def page_login() -> None:
ui.add_head_html('''
<link rel="manifest" href="/manifest.json">
''')
ui.add_body_html(''' <button id="btnAdd" style="display: none;">Install our app!</button>
<script>
let deferredPrompt;
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 notify the user they can add to home screen
btnAdd.style.display = 'block';
});
btnAdd.addEventListener('click', (e) => {
// hide our user interface that shows our A2HS button
btnAdd.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>''')
async def alert():
await ui.run_javascript('''
// 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;
});''', respond=False)
with ui.card().classes('absolute-center items-center'):
ui.button('Install App', on_click=alert)
ui.image('assets/logo.svg')
ui.label('Let\'s Swing Admin').classes('text-2xl')
username = ui.input('Username').on('keydown.enter', try_login).classes('w-full')

Loading…
Cancel
Save