Spaces:
Running
Running
File size: 1,519 Bytes
85d3b29 1a7d583 85d3b29 1a7d583 85d3b29 1a7d583 85d3b29 1a7d583 85d3b29 1a7d583 85d3b29 1a7d583 85d3b29 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import os
import sys
import gradio as gr
import json
from assets.i18n.i18n import I18nAuto
from assets.discord_presence import RPCManager
now_dir = os.getcwd()
sys.path.append(now_dir)
i18n = I18nAuto()
config_file = os.path.join(now_dir, "assets", "config.json")
def load_config_presence():
with open(config_file, "r", encoding="utf8") as file:
config = json.load(file)
return config["discord_presence"]
def save_config(value):
with open(config_file, "r", encoding="utf8") as file:
config = json.load(file)
config["discord_presence"] = value
with open(config_file, "w", encoding="utf8") as file:
json.dump(config, file, indent=2)
def presence_tab():
with gr.Row():
with gr.Column():
presence = gr.Checkbox(
label=i18n("Enable Applio integration with Discord presence"),
info=i18n(
"It will activate the possibility of displaying the current Applio activity in Discord."
),
interactive=True,
value=load_config_presence(),
)
presence.change(
fn=toggle,
inputs=[presence],
outputs=[],
)
def toggle(checkbox):
save_config(bool(checkbox))
if load_config_presence() == True:
try:
RPCManager.start_presence()
except KeyboardInterrupt:
RPCManager.stop_presence()
else:
RPCManager.stop_presence()
|