mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-19 00:13:35 +08:00
Opt: Refactor discord rpc
This commit is contained in:
10
gui.py
10
gui.py
@@ -1,14 +1,20 @@
|
|||||||
import threading
|
import threading
|
||||||
|
from multiprocessing import Event, Process
|
||||||
from multiprocessing import Process, Event
|
|
||||||
|
|
||||||
|
|
||||||
def func(ev: threading.Event):
|
def func(ev: threading.Event):
|
||||||
import argparse
|
import argparse
|
||||||
|
import asyncio
|
||||||
|
import sys
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
from module.webui.app import app
|
from module.webui.app import app
|
||||||
from module.webui.setting import State
|
from module.webui.setting import State
|
||||||
|
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
||||||
|
|
||||||
State.researt_event = ev
|
State.researt_event = ev
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Alas web service")
|
parser = argparse.ArgumentParser(description="Alas web service")
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
|
import asyncio
|
||||||
import time
|
import time
|
||||||
from multiprocessing import Process
|
|
||||||
|
|
||||||
from pypresence import Presence
|
from pypresence import AioPresence
|
||||||
|
|
||||||
process: Process = None
|
RPC = AioPresence("929437173764223057")
|
||||||
|
|
||||||
|
|
||||||
def run():
|
async def run():
|
||||||
APPLICATION_ID = "929437173764223057"
|
await RPC.connect()
|
||||||
RPC = Presence(APPLICATION_ID)
|
await RPC.update(state="Alas is playing Azurlane", start=time.time(), large_image="alas")
|
||||||
RPC.connect()
|
|
||||||
RPC.update(state="Alas is playing Azurlane", start=time.time(), large_image="alas")
|
|
||||||
|
|
||||||
|
|
||||||
def init_discord_rpc():
|
def init_discord_rpc():
|
||||||
global process
|
asyncio.create_task(run())
|
||||||
if process is None:
|
|
||||||
process = Process(target=run)
|
|
||||||
process.start()
|
|
||||||
|
|
||||||
|
|
||||||
def close_discord_rpc():
|
def close_discord_rpc():
|
||||||
global process
|
RPC.close()
|
||||||
if process is not None:
|
|
||||||
process.terminate()
|
|
||||||
process = None
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from module.config.utils import *
|
from module.config.utils import *
|
||||||
from module.webui.config import DeployConfig
|
from module.webui.setting import State
|
||||||
|
|
||||||
LANG = "zh-CN"
|
LANG = "zh-CN"
|
||||||
TRANSLATE_MODE = False
|
TRANSLATE_MODE = False
|
||||||
@@ -17,7 +17,7 @@ def set_language(s: str, refresh=False):
|
|||||||
else:
|
else:
|
||||||
LANG = "en-US"
|
LANG = "en-US"
|
||||||
|
|
||||||
DeployConfig().Language = LANG
|
State.deploy_config.Language = LANG
|
||||||
|
|
||||||
if refresh:
|
if refresh:
|
||||||
from pywebio.session import run_js
|
from pywebio.session import run_js
|
||||||
|
|||||||
Reference in New Issue
Block a user