Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the python script #9

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixed the standby glitch(rpc doesn't clear)
LeNooby 09 committed Oct 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f4916fd5e907d807fab64653c5a22d2c8f29215d
17 changes: 10 additions & 7 deletions PresenceClient/PresenceClient-Py/presence-client.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@

load_dotenv() # load environment variables from .env file

switch_ip = os.getenv('IP') #gets the IP from the environment variable #
client_id = os.getenv('APPLICATION_ID') #gets the client ID from the environment variable # Made them global variables so they can be used in the Title class
#
rpc = Presence(str(client_id)) # also rpc is here to clear and close it in the title class(if that deosn't work the script will restart lol)

TCP_PORT = 0xCAFE
PACKETMAGIC = 0xFFAADD23

@@ -31,7 +36,9 @@
class Title:
def __init__(self, raw_data):
if len(raw_data) != 628: #checks if the data is the correct length
return
rpc.clear() #clears the RPC
rpc.close() #closes the RPC
os.system('python3 presence-client.py --ignore-home-screen') #restarts the script(best way to reinitialize the title packet(i have no idea how to do it otherwise))
unpacker = struct.Struct('2L612s')
enc_data = unpacker.unpack(raw_data)
self.magic = int(enc_data[0])
@@ -52,13 +59,10 @@ def __init__(self, raw_data):

def main():
consoleargs = parser.parse_args()
switch_ip = os.getenv('IP') #gets the IP from the environment variable
client_id = os.getenv('APPLICATION_ID') #gets the client ID from the environment variable
if not checkIP(switch_ip):
print('Invalid IP')
exit()

rpc = Presence(str(client_id))
try:
rpc.connect()
rpc.clear()
@@ -73,8 +77,8 @@ def main():
break
except socket.error as e:
print(f'Error connecting to {switch_ip}:{TCP_PORT}. Retrying in 1 minute.')
rpc.clear()
time.sleep(60) #wait 1 minute before retrying
os.system('python3 presence-client.py --ignore-home-screen')
lastProgramName = ''
startTimer = 0
while True:
@@ -151,6 +155,5 @@ def checkIP(ip):
def iconFromPid(pid):
return '0' + str(hex(int(pid))).split('0x')[1]


if __name__ == '__main__':
main()
main()