arreglando script de solicitud de permisos
Browse files- app/main.py +28 -16
app/main.py
CHANGED
|
@@ -121,14 +121,21 @@ def bot_broadcast(msg):
|
|
| 121 |
|
| 122 |
def start_bot_thread():
|
| 123 |
if bot:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
try: bot.delete_webhook()
|
| 125 |
except: pass
|
|
|
|
| 126 |
while True:
|
| 127 |
try:
|
|
|
|
| 128 |
bot.infinity_polling(timeout=20, long_polling_timeout=10)
|
| 129 |
except Exception as e:
|
| 130 |
-
print(f"Error DNS/Red: {e}. Reintento en
|
| 131 |
-
time.sleep(
|
| 132 |
|
| 133 |
if bot:
|
| 134 |
threading.Thread(target=start_bot_thread, daemon=True).start()
|
|
@@ -136,12 +143,16 @@ if bot:
|
|
| 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
|
| 141 |
-
|
| 142 |
-
Notification
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
def mostrar_notificacion(texto, color="blue"):
|
| 147 |
# Notificación en la app (SnackBar)
|
|
@@ -149,15 +160,16 @@ def main(page: ft.Page):
|
|
| 149 |
page.overlay.append(snack)
|
| 150 |
snack.open = True
|
| 151 |
|
| 152 |
-
# Notificación de Sistema/Navegador (vía JS)
|
| 153 |
-
page
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
| 161 |
|
| 162 |
page.update()
|
| 163 |
|
|
|
|
| 121 |
|
| 122 |
def start_bot_thread():
|
| 123 |
if bot:
|
| 124 |
+
# Retraso inicial para Hugging Face: permite que las instancias viejas se apaguen
|
| 125 |
+
# y suelten el polling antes de que esta nueva intente conectar (Evita 409 Conflict)
|
| 126 |
+
print("INFO: Esperando 15s para estabilizar conexión con Telegram...")
|
| 127 |
+
time.sleep(15)
|
| 128 |
+
|
| 129 |
try: bot.delete_webhook()
|
| 130 |
except: pass
|
| 131 |
+
|
| 132 |
while True:
|
| 133 |
try:
|
| 134 |
+
print("DEBUG: Iniciando polling de Telegram...")
|
| 135 |
bot.infinity_polling(timeout=20, long_polling_timeout=10)
|
| 136 |
except Exception as e:
|
| 137 |
+
print(f"Error DNS/Red/Conflicto: {e}. Reintento en 30s...")
|
| 138 |
+
time.sleep(30)
|
| 139 |
|
| 140 |
if bot:
|
| 141 |
threading.Thread(target=start_bot_thread, daemon=True).start()
|
|
|
|
| 143 |
def main(page: ft.Page):
|
| 144 |
page.title = "MAKERSPACE DATABASE"
|
| 145 |
# Solicitar permiso para notificaciones de navegador/sistema (vía JS)
|
| 146 |
+
# Solicitar permiso para notificaciones de navegador/sistema (vía JS seguro)
|
| 147 |
def pedir_permiso_notif(e=None):
|
| 148 |
+
if hasattr(page, "run_javascript"):
|
| 149 |
+
page.run_javascript("""
|
| 150 |
+
if ("Notification" in window) {
|
| 151 |
+
Notification.requestPermission();
|
| 152 |
+
}
|
| 153 |
+
""")
|
| 154 |
+
else:
|
| 155 |
+
mostrar_notificacion("⚠️ Tu navegador no soporta alertas nativas")
|
| 156 |
|
| 157 |
def mostrar_notificacion(texto, color="blue"):
|
| 158 |
# Notificación en la app (SnackBar)
|
|
|
|
| 160 |
page.overlay.append(snack)
|
| 161 |
snack.open = True
|
| 162 |
|
| 163 |
+
# Notificación de Sistema/Navegador (vía JS seguro)
|
| 164 |
+
if hasattr(page, "run_javascript"):
|
| 165 |
+
page.run_javascript(f"""
|
| 166 |
+
if ("Notification" in window && Notification.permission === "granted") {{
|
| 167 |
+
new Notification("MAKER STATION", {{
|
| 168 |
+
body: "{texto}",
|
| 169 |
+
icon: "/icon192x192.png"
|
| 170 |
+
}});
|
| 171 |
+
}}
|
| 172 |
+
""")
|
| 173 |
|
| 174 |
page.update()
|
| 175 |
|