Skip to content

Commit

Permalink
Merge pull request #69 from Its-Haze/v3.1.1-improvements
Browse files Browse the repository at this point in the history
start application faster and try to reconnect to the API if the client is still running
  • Loading branch information
Its-Haze authored Dec 1, 2024
2 parents c705f50 + ef19647 commit 64532be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion league_rpc/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Set version number of package."""

__version__ = "v3.1.0"
__version__ = "v3.1.1"
import requests

RELEASES_PAGE = "https://github.com/Its-Haze/league-rpc/releases"
Expand Down
19 changes: 14 additions & 5 deletions league_rpc/lcu_api/lcu_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from league_rpc.models.module_data import ModuleData
from league_rpc.models.rpc_data import RPCData
from league_rpc.models.rpc_updater import RPCUpdater
from league_rpc.processes.process import processes_exists

module_data = ModuleData(
client_data=ClientData(),
Expand All @@ -39,21 +40,20 @@ async def connect(connection: Connection) -> None:
logger.info("Connected to the League Client API.")
logger.update_progress_bar(advance=20)

time.sleep(1) # Give the client some time to load
time.sleep(0.5) # Give the client some time to load
logger.update_progress_bar(advance=10)

time.sleep(1) # Give the client some time to load
time.sleep(0.5) # Give the client some time to load
logger.update_progress_bar(advance=10)

time.sleep(1)
time.sleep(0.5)
logger.update_progress_bar(advance=20)

time.sleep(2)
await gather_base_data(connection=connection, module_data=module_data)
logger.info("Successfully gathered base data.")
logger.update_progress_bar(advance=30)

time.sleep(1)
rpc_updater.delay_update(module_data=module_data, connection=connection)
logger.info("Discord RPC successfully updated")
logger.update_progress_bar(advance=40)
Expand All @@ -74,7 +74,16 @@ async def disconnect(_: Connection) -> None:
"""
logger = module_data.logger
logger.info("Disconnected from the League Client API.", color="red")
await module_data.connector.stop()

league_processes: list[str] = ["LeagueClient.exe", "LeagueClientUx.exe"]

logger.info(
"Will attemt to reconnect in 5 seconds, if the client is still running."
)
time.sleep(5)
if not processes_exists(league_processes):
logger.info("League Client is closed. Stopping the connector.")
await module_data.connector.stop()


@module_data.connector.ws.register( # type:ignore
Expand Down
14 changes: 8 additions & 6 deletions league_rpc/models/rpc_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def trigger_rpc_update(
"""

# Debugging what function called trigger_rpc_update
stack = inspect.stack()
caller = stack[1].function
module_data.logger.debug(f"Caller of trigger_rpc_update: {caller}")
if module_data.cli_args.debug: # type:ignore
stack = inspect.stack()
caller = stack[1].function
module_data.logger.debug(f"Caller of trigger_rpc_update: {caller}")

if self.has_rpc_data_changed(module_data.rpc_data):
self.previous_rpc_data = copy.copy(module_data.rpc_data)
Expand Down Expand Up @@ -114,9 +115,10 @@ def delay_update(
"""Schedules an update if one is not already scheduled within a short delay (1 second)."""

# Debugging what function called delay_update
inspect.stack()
caller = inspect.stack()[1].function
module_data.logger.debug(f"Caller in delay_update: {caller}")
if module_data.cli_args.debug: # type:ignore
inspect.stack()
caller = inspect.stack()[1].function
module_data.logger.debug(f"Caller in delay_update: {caller}")

# Check if the client data has changed
if self.has_client_data_changed(module_data.client_data):
Expand Down
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ requests==2.31.0
nest_asyncio==1.5.8

# just wait for lcu-driver==3.0.3 to be released
# 8mb non-debug mode.
git+https://github.com/its-haze/[email protected]#egg=lcu-driver


# debug 4mb
#git+https://github.com/its-haze/lcu-driver.git@cecf19036b6c2520eb6d0ccb0cc48a97fa452f9a#egg=lcu-driver

# debug 8mb
#git+https://github.com/its-haze/lcu-driver.git@31542a602551d038b008df8fea3a238bf89a33d2#egg=lcu-driver

# debug 64mb
#git+https://github.com/its-haze/lcu-driver.git@60602fe3d1659d47e6e238b0f2b743a1b646420d#egg=lcu-driver

rich==13.7.1

0 comments on commit 64532be

Please sign in to comment.