Edoruin commited on
Commit
676a7ca
·
1 Parent(s): 21a86c5

arreglando script de solicitud de permisos

Browse files
Files changed (1) hide show
  1. app/main.py +18 -18
app/main.py CHANGED
@@ -135,13 +135,13 @@ if bot:
135
 
136
  def main(page: ft.Page):
137
  page.title = "MAKERSPACE DATABASE"
138
- page.theme_mode = ft.ThemeMode.DARK
139
- page.padding = 10
140
-
141
- # Solicitar permiso para notificaciones de navegador/sistema
142
- try:
143
- page.get_notification_permission()
144
- except: pass
145
 
146
  def mostrar_notificacion(texto, color="blue"):
147
  # Notificación en la app (SnackBar)
@@ -149,15 +149,15 @@ def main(page: ft.Page):
149
  page.overlay.append(snack)
150
  snack.open = True
151
 
152
- # Notificación de Sistema/Navegador
153
- try:
154
- # Intentamos lanzar notificación nativa si hay permiso
155
- page.show_notification(
156
- title="MAKER STATION",
157
- body=texto,
158
- icon="/icon192x192.png"
159
- )
160
- except: pass
161
 
162
  page.update()
163
 
@@ -207,7 +207,7 @@ def main(page: ft.Page):
207
  content=ft.Column([
208
  ft.Text(f"ESTADO: {i.get('status_loan', 'PENDING')}", color=status_color, weight="bold"),
209
  ft.Divider(),
210
- ft.Text(f"ALUMNO: {i['alumno']}", size=16),
211
  ft.Text(f"ITEM: {i['item']}", weight="bold"),
212
  ft.Text(f"CANTIDAD: {i['cantidad']}"),
213
  ft.Divider(),
@@ -359,7 +359,7 @@ def main(page: ft.Page):
359
  ft.Row([
360
  ft.Text("SOLICITAR PRÉSTAMO", size=18, weight="bold"),
361
  ft.ElevatedButton("🔔 ACTIVAR ALERTAS", icon=ft.Icons.NOTIFICATIONS_ACTIVE,
362
- on_click=lambda _: page.get_notification_permission(), bgcolor=ft.Colors.BLUE_GREY_900)
363
  ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN),
364
 
365
  nombre,
 
135
 
136
  def main(page: ft.Page):
137
  page.title = "MAKERSPACE DATABASE"
138
+ # Solicitar permiso para notificaciones de navegador/sistema (vía JS)
139
+ def pedir_permiso_notif(e=None):
140
+ page.run_javascript("""
141
+ if ("Notification" in window) {
142
+ Notification.requestPermission();
143
+ }
144
+ """)
145
 
146
  def mostrar_notificacion(texto, color="blue"):
147
  # Notificación en la app (SnackBar)
 
149
  page.overlay.append(snack)
150
  snack.open = True
151
 
152
+ # Notificación de Sistema/Navegador (vía JS)
153
+ page.run_javascript(f"""
154
+ if ("Notification" in window && Notification.permission === "granted") {{
155
+ new Notification("MAKER STATION", {{
156
+ body: "{texto}",
157
+ icon: "/icon192x192.png"
158
+ }});
159
+ }}
160
+ """)
161
 
162
  page.update()
163
 
 
207
  content=ft.Column([
208
  ft.Text(f"ESTADO: {i.get('status_loan', 'PENDING')}", color=status_color, weight="bold"),
209
  ft.Divider(),
210
+ ft.Text(f"SOLICITANTE: {i.get('Solicitante', i.get('alumno', '---'))}", size=16),
211
  ft.Text(f"ITEM: {i['item']}", weight="bold"),
212
  ft.Text(f"CANTIDAD: {i['cantidad']}"),
213
  ft.Divider(),
 
359
  ft.Row([
360
  ft.Text("SOLICITAR PRÉSTAMO", size=18, weight="bold"),
361
  ft.ElevatedButton("🔔 ACTIVAR ALERTAS", icon=ft.Icons.NOTIFICATIONS_ACTIVE,
362
+ on_click=pedir_permiso_notif, bgcolor=ft.Colors.BLUE_GREY_900)
363
  ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN),
364
 
365
  nombre,