59 lines
1.5 KiB
Python
Executable File
59 lines
1.5 KiB
Python
Executable File
import asyncio
|
|
from nicegui import ui, app
|
|
from ui import layout, dashboard, settings, manual_tools
|
|
from database import init_db
|
|
from core.bot import TelegramManager
|
|
from core.watcher import DirectoryWatcher
|
|
from core.state import state
|
|
|
|
# Inicializa Banco
|
|
init_db()
|
|
|
|
# Instâncias Globais
|
|
bot = TelegramManager()
|
|
watcher = DirectoryWatcher(bot)
|
|
|
|
# --- LIFECYCLE ---
|
|
async def startup():
|
|
# 1. Inicia o Watcher (Ele começa pausado, safe)
|
|
asyncio.create_task(watcher.start())
|
|
|
|
# 2. Inicia o Bot com atraso e em background
|
|
# Isso evita que a falha de conexão trave a UI
|
|
asyncio.create_task(delayed_bot_start())
|
|
|
|
async def delayed_bot_start():
|
|
print("⏳ Aguardando rede estabilizar (5s)...")
|
|
await asyncio.sleep(5)
|
|
await bot.start()
|
|
|
|
async def shutdown():
|
|
await bot.stop()
|
|
|
|
app.on_startup(startup)
|
|
app.on_shutdown(shutdown)
|
|
|
|
# --- ROTAS ---
|
|
@ui.page('/')
|
|
def index_page():
|
|
ui.colors(primary='#5898d4', secondary='#263238')
|
|
ui.page_title('Clei-Flow')
|
|
layout.create_interface()
|
|
dashboard.show()
|
|
|
|
@ui.page('/settings')
|
|
def settings_page():
|
|
ui.colors(primary='#5898d4', secondary='#263238')
|
|
ui.page_title('Configurações')
|
|
layout.create_interface()
|
|
settings.show()
|
|
|
|
@ui.page('/explorer')
|
|
def explorer_page():
|
|
ui.colors(primary='#5898d4', secondary='#263238')
|
|
ui.page_title('Explorador')
|
|
layout.create_interface()
|
|
manual_tools.show()
|
|
|
|
if __name__ in {"__main__", "__mp_main__"}:
|
|
ui.run(title='Clei-Flow', port=8080, storage_secret='clei-secret', reload=True) |