Skip to content

Commit

Permalink
Merge pull request #236 from SecSchool/fix-windows-stuff
Browse files Browse the repository at this point in the history
Fix windows rpc close & broken ipc pipe detection
  • Loading branch information
qwertyquerty authored Mar 2, 2024
2 parents 9dfbe5a + b493893 commit 9562a8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pypresence/presence.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import time
import sys

from .baseclient import BaseClient
from .payloads import Payload
Expand Down Expand Up @@ -44,8 +45,10 @@ def connect(self):

def close(self):
self.send_data(2, {'v': 1, 'client_id': self.client_id})
self.sock_writer.close()
self.loop.close()
self.sock_writer.close()
if sys.platform == 'win32' or sys.platform == 'win64':
self.sock_writer._call_connection_lost(None)


class AioPresence(BaseClient):
Expand Down Expand Up @@ -81,5 +84,7 @@ async def connect(self):

def close(self):
self.send_data(2, {'v': 1, 'client_id': self.client_id})
self.sock_writer.close()
self.loop.close()
self.sock_writer.close()
if sys.platform == 'win32' or sys.platform == 'win64':
self.sock_writer._call_connection_lost(None)
8 changes: 7 additions & 1 deletion pypresence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def remove_none(d: dict):
return d


def test_ipc_path(path):
'''Tests an IPC pipe to ensure that it actually works'''
with open(path):
return True


# Returns on first IPC pipe matching Discord's
def get_ipc_path(pipe=None):
ipc = 'discord-ipc-'
Expand All @@ -40,7 +46,7 @@ def get_ipc_path(pipe=None):
full_path = os.path.abspath(os.path.join(tempdir, path))
if sys.platform == 'win32' or os.path.isdir(full_path):
for entry in os.scandir(full_path):
if entry.name.startswith(ipc) and os.path.exists(entry):
if entry.name.startswith(ipc) and os.path.exists(entry) and test_ipc_path(entry):
return entry.path


Expand Down

0 comments on commit 9562a8c

Please sign in to comment.