Hi,
I ended up doing this (it works):
@app.callback(
[Output('navlink-tab6', 'disabled'),
Output('url', 'new_pathname')],
Input('url', 'pathname'),
prevent_initial_call=False
)
def update_navlink_tab7(pathname):
# Obtén el estado de PokerStars
pokerstars_abierto = check_pokerstars()
global disableds
new_pathname = pathname
if pathname == '/page-7' and pokerstars_abierto == True:
#cerrar_navegador()
sys.exit()
else:
if pokerstars_abierto == True:
disableds = True
print("0k stars is opened")
else:
disableds = False
print("0k, PokerStars is not opened")
return disableds ,new_pathname
# Diseño del contenido principal
content = html.Div(id='page-content', style={'margin-left': '250px', 'padding': '20px'})
# Diseño de la aplicación completa
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='output-data-upload'),
dcc.Store(id='intermediate-value'),
dcc.Store(id='paquito'),
html.Br(),
sidebar,
content,
dcc.Interval(id='interval-component', interval=5*1000, n_intervals=0)
])
##########################################################################################
# Callback para cerrar la aplicación si PokerStars está abierto
@app.callback(
[Output('navlink-tab6', 'children'),
Output('interval-component', 'interval')],
[Input('interval-component', 'n_intervals')],
prevent_initial_call=True
)
def close_app_if_required(n_intervals):
pokerstars_abierto = check_pokerstars()
print(f"n_intervals: {n_intervals}, pokerstars_abierto: {pokerstars_abierto}")
if n_intervals > 0 and pokerstars_abierto:
print("Cerrando la aplicación en", datetime.now())
cerrar_navegador()
sys.exit()
raise PreventUpdate("La aplicación se cerró debido a PokerStars.")
else:
print("Manteniendo el enlace habilitado")
return html.Div([html.H5("Rango")]), 5*1000 # Vuelve a habilitar el enlace y muestra el nombre original, y reinicia el intervalo
def check_pokerstars():
pokerstars_abierto = False
if platform.system() == 'Windows':
for process in psutil.process_iter(['pid', 'name']):
if nombre_del_proceso_pokerstars.lower() in process.info['name'].lower():
pokerstars_abierto = True
print("PokerStars abierto")
break
return pokerstars_abierto