mirror of
https://github.com/derrod/legendary.git
synced 2025-08-28 04:21:01 +00:00
comment code
This commit is contained in:
parent
92830f061c
commit
e4994ec5b0
|
@ -514,6 +514,7 @@ class LegendaryCLI:
|
||||||
if env:
|
if env:
|
||||||
logger.debug('Environment overrides:', env)
|
logger.debug('Environment overrides:', env)
|
||||||
|
|
||||||
|
# Variable to tell the Discord RPC to disconnect
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
ns = manager.Namespace()
|
ns = manager.Namespace()
|
||||||
ns.finish_rpc = False
|
ns.finish_rpc = False
|
||||||
|
@ -523,8 +524,10 @@ class LegendaryCLI:
|
||||||
rpc.start()
|
rpc.start()
|
||||||
|
|
||||||
game_process = subprocess.Popen(params, cwd=cwd, env=env)
|
game_process = subprocess.Popen(params, cwd=cwd, env=env)
|
||||||
|
# Wait for game process to end
|
||||||
game_process.wait()
|
game_process.wait()
|
||||||
|
|
||||||
|
# Tell Discord RPC to stop if it's running
|
||||||
if not args.disable_rpc:
|
if not args.disable_rpc:
|
||||||
ns.finish_rpc = True
|
ns.finish_rpc = True
|
||||||
rpc.join()
|
rpc.join()
|
||||||
|
@ -532,18 +535,24 @@ class LegendaryCLI:
|
||||||
|
|
||||||
def startRPC(self, app_name, ns):
|
def startRPC(self, app_name, ns):
|
||||||
try:
|
try:
|
||||||
|
# Discord app Client ID goes here
|
||||||
|
# A Discord app can be made at https://discord.com/developers/applications
|
||||||
RPC = Presence('828711025863688192')
|
RPC = Presence('828711025863688192')
|
||||||
RPC.connect()
|
RPC.connect()
|
||||||
|
|
||||||
|
# Get readable app title from app name
|
||||||
app_title = self.core.get_game(app_name).app_title
|
app_title = self.core.get_game(app_name).app_title
|
||||||
|
|
||||||
|
# Start time of playing game
|
||||||
start = str(time.time()).split(".")[0]
|
start = str(time.time()).split(".")[0]
|
||||||
RPC.update(large_image="legendarylogo", large_text=app_title, state="via Legendary on " + platform.system(), details=app_title, start=start)
|
RPC.update(large_image="legendarylogo", large_text=app_title, state="via Legendary on " + platform.system(), details=app_title, start=start)
|
||||||
|
|
||||||
|
# This will block forever until ns.finish_rpc is True so that the Discord RPC doesn't disconnect, but this is fine since this function is run in parallel as a separate process
|
||||||
while not ns.finish_rpc:
|
while not ns.finish_rpc:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# Catch all errors, like not being able to detect Discord, and display a warning
|
||||||
print(f'Warning: {e} on Discord RPC start')
|
print(f'Warning: {e} on Discord RPC start')
|
||||||
|
|
||||||
def install_game(self, args):
|
def install_game(self, args):
|
||||||
|
|
Loading…
Reference in a new issue