mirror of
https://github.com/derrod/legendary.git
synced 2025-08-28 04:21:01 +00:00
Add Discord RPC to legendary
This commit is contained in:
parent
313323e43a
commit
b59de25bce
|
@ -1,4 +1,4 @@
|
||||||
"""Legendary!"""
|
"""Legendary!"""
|
||||||
|
|
||||||
__version__ = '0.20.6'
|
__version__ = '0.20.7'
|
||||||
__codename__ = 'A Red Letter Day'
|
__codename__ = 'A Red Letter Day'
|
||||||
|
|
|
@ -10,11 +10,17 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
from pypresence import Presence
|
||||||
|
import platform
|
||||||
|
# import threading
|
||||||
|
import psutil
|
||||||
|
# import asyncio
|
||||||
|
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
from logging.handlers import QueueListener
|
from logging.handlers import QueueListener
|
||||||
from multiprocessing import freeze_support, Queue as MPQueue
|
from multiprocessing import freeze_support, Queue as MPQueue
|
||||||
|
from multiprocessing import Process
|
||||||
from sys import exit, stdout
|
from sys import exit, stdout
|
||||||
|
|
||||||
from legendary import __version__, __codename__
|
from legendary import __version__, __codename__
|
||||||
|
@ -510,8 +516,47 @@ class LegendaryCLI:
|
||||||
logger.debug(f'Working directory: {cwd}')
|
logger.debug(f'Working directory: {cwd}')
|
||||||
if env:
|
if env:
|
||||||
logger.debug('Environment overrides:', env)
|
logger.debug('Environment overrides:', env)
|
||||||
|
|
||||||
|
rpc = Process(target=self.startRPC, args=(app_name, params))
|
||||||
|
rpc.start()
|
||||||
|
|
||||||
subprocess.Popen(params, cwd=cwd, env=env)
|
subprocess.Popen(params, cwd=cwd, env=env)
|
||||||
|
|
||||||
|
def startRPC(self, app_name, params):
|
||||||
|
try:
|
||||||
|
RPC = Presence('828711025863688192')
|
||||||
|
RPC.connect()
|
||||||
|
|
||||||
|
app_title = self.core.get_game(app_name).app_title
|
||||||
|
|
||||||
|
exe_name = None
|
||||||
|
for i in range(len(params)):
|
||||||
|
if params[i].endswith('.exe'):
|
||||||
|
exe_name = os.path.basename(params[i])
|
||||||
|
break
|
||||||
|
|
||||||
|
if exe_name is not None:
|
||||||
|
start = str(time.time()).split(".")[0]
|
||||||
|
RPC.update(large_image="legendarylogofull", large_text=app_title, state="via Legendary on " + platform.system(), details=app_title, start=start)
|
||||||
|
while True:
|
||||||
|
game_running = False
|
||||||
|
pids = psutil.pids()
|
||||||
|
for i in range(len(pids)):
|
||||||
|
try:
|
||||||
|
p = psutil.Process(pids[i])
|
||||||
|
if p.cmdline()[0].find(exe_name) != -1:
|
||||||
|
# Game is running
|
||||||
|
game_running = True
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if game_running is True:
|
||||||
|
time.sleep(5)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(f'Warning: {e} on Discord RPC start')
|
||||||
|
|
||||||
def install_game(self, args):
|
def install_game(self, args):
|
||||||
if self.core.is_installed(args.app_name):
|
if self.core.is_installed(args.app_name):
|
||||||
igame = self.core.get_installed_game(args.app_name)
|
igame = self.core.get_installed_game(args.app_name)
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -36,7 +36,9 @@ setup(
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'requests<3.0',
|
'requests<3.0',
|
||||||
'setuptools',
|
'setuptools',
|
||||||
'wheel'
|
'wheel',
|
||||||
|
'pypresence',
|
||||||
|
'psutil'
|
||||||
],
|
],
|
||||||
url='https://github.com/derrod/legendary',
|
url='https://github.com/derrod/legendary',
|
||||||
description='Free and open-source replacement for the Epic Games Launcher application',
|
description='Free and open-source replacement for the Epic Games Launcher application',
|
||||||
|
|
Loading…
Reference in a new issue