diff --git a/pypresence/presence.py b/pypresence/presence.py index 51e9e7d..8490ece 100644 --- a/pypresence/presence.py +++ b/pypresence/presence.py @@ -1,6 +1,7 @@ import json import os import time +import sys from .baseclient import BaseClient from .payloads import Payload @@ -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): @@ -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) diff --git a/pypresence/utils.py b/pypresence/utils.py index 9af1fc4..83b6180 100644 --- a/pypresence/utils.py +++ b/pypresence/utils.py @@ -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-' @@ -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