From 0714ba49e8082e121f3d91929a79b66b47b88ec7 Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Mon, 11 Mar 2024 18:23:46 +0100 Subject: [PATCH 1/3] fix: fix test_ipc_path for linux. Signed-off-by: NikOverflow --- pypresence/utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pypresence/utils.py b/pypresence/utils.py index 83b6180..7d86ce2 100644 --- a/pypresence/utils.py +++ b/pypresence/utils.py @@ -5,6 +5,7 @@ import sys import tempfile import time +import socket from .exceptions import PyPresenceException @@ -23,8 +24,13 @@ def remove_none(d: dict): def test_ipc_path(path): '''Tests an IPC pipe to ensure that it actually works''' - with open(path): - return True + if sys.platform == 'win32' or sys.platform == 'win64': + with open(path): + return True + else: + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: + client.connect(path) + return True # Returns on first IPC pipe matching Discord's @@ -46,7 +52,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) and test_ipc_path(entry): + if entry.name.startswith(ipc) and os.path.exists(entry) and test_ipc_path(entry.path): return entry.path From 966630a8f81f9dee1932ecaed7cbb77125513df5 Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Mon, 11 Mar 2024 18:26:21 +0100 Subject: [PATCH 2/3] fix: fix #216 Signed-off-by: NikOverflow --- pypresence/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypresence/utils.py b/pypresence/utils.py index 7d86ce2..2b8f66a 100644 --- a/pypresence/utils.py +++ b/pypresence/utils.py @@ -40,7 +40,7 @@ def get_ipc_path(pipe=None): ipc = f"{ipc}{pipe}" if sys.platform in ('linux', 'darwin'): - tempdir = (os.environ.get('XDG_RUNTIME_DIR') or tempfile.gettempdir()) + tempdir = os.environ.get('XDG_RUNTIME_DIR') or (f"/run/user/{os.getuid()}" if os.path.exists(f"/run/user/{os.getuid()}") else tempfile.gettempdir()) paths = ['.', 'snap.discord', 'app/com.discordapp.Discord', 'app/com.discordapp.DiscordCanary'] elif sys.platform == 'win32': tempdir = r'\\?\pipe' From 90cc54f7409d14e8fe09ea132a8c4fc691e933e1 Mon Sep 17 00:00:00 2001 From: Niklas S Date: Mon, 11 Mar 2024 21:15:10 +0100 Subject: [PATCH 3/3] fix: fix exception. --- pypresence/presence.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pypresence/presence.py b/pypresence/presence.py index 8490ece..54ff57a 100644 --- a/pypresence/presence.py +++ b/pypresence/presence.py @@ -46,7 +46,6 @@ def connect(self): def close(self): self.send_data(2, {'v': 1, 'client_id': self.client_id}) self.loop.close() - self.sock_writer.close() if sys.platform == 'win32' or sys.platform == 'win64': self.sock_writer._call_connection_lost(None) @@ -85,6 +84,5 @@ async def connect(self): def close(self): self.send_data(2, {'v': 1, 'client_id': self.client_id}) self.loop.close() - self.sock_writer.close() if sys.platform == 'win32' or sys.platform == 'win64': self.sock_writer._call_connection_lost(None)