From 530e799719328b0707260ebb53804140af842a96 Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Fri, 1 Mar 2024 17:13:34 +0100 Subject: [PATCH 1/5] fix: fix windows error if the ipc file can't be used. Signed-off-by: NikOverflow --- pypresence/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pypresence/utils.py b/pypresence/utils.py index 31e00a8..ede9ccd 100644 --- a/pypresence/utils.py +++ b/pypresence/utils.py @@ -21,6 +21,15 @@ def remove_none(d: dict): return d +def test_ipc_path(path): + '''Tests an IPC pipe to ensure that it actually works''' + try: + with open(path): + return True + except Exception: + return False + + # Returns on first IPC pipe matching Discord's def get_ipc_path(pipe=None): ipc = 'discord-ipc-' @@ -40,7 +49,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 From 9621278f6b1805da9e69858ad9a58e4670c508b4 Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Fri, 1 Mar 2024 19:23:40 +0100 Subject: [PATCH 2/5] fix: fix rpc close for windows. Signed-off-by: NikOverflow --- pypresence/presence.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pypresence/presence.py b/pypresence/presence.py index 51e9e7d..bc55a98 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 @@ -81,5 +82,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) From c7009dbae207dec4e96c2984e7d1220d4585763e Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Fri, 1 Mar 2024 19:51:05 +0100 Subject: [PATCH 3/5] fix: fix rpc close for windows on the rich presence itself. Signed-off-by: NikOverflow --- pypresence/presence.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pypresence/presence.py b/pypresence/presence.py index bc55a98..8490ece 100644 --- a/pypresence/presence.py +++ b/pypresence/presence.py @@ -45,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): From f10fb9efc3a5eeecaa11ea72863ec8334a71a36c Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Sat, 2 Mar 2024 11:42:05 +0100 Subject: [PATCH 4/5] feat: let test_ipc_path throw the error. Signed-off-by: NikOverflow --- pypresence/utils.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pypresence/utils.py b/pypresence/utils.py index ede9ccd..463d556 100644 --- a/pypresence/utils.py +++ b/pypresence/utils.py @@ -23,12 +23,8 @@ def remove_none(d: dict): def test_ipc_path(path): '''Tests an IPC pipe to ensure that it actually works''' - try: - with open(path): - return True - except Exception: - return False - + with open(path): + return True # Returns on first IPC pipe matching Discord's def get_ipc_path(pipe=None): From b4938937271dd9be36c96d17a01549fc8e01c17f Mon Sep 17 00:00:00 2001 From: NikOverflow Date: Sat, 2 Mar 2024 11:46:19 +0100 Subject: [PATCH 5/5] refactor: fix the linting. Signed-off-by: NikOverflow --- pypresence/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pypresence/utils.py b/pypresence/utils.py index 463d556..edff9f4 100644 --- a/pypresence/utils.py +++ b/pypresence/utils.py @@ -26,6 +26,7 @@ def test_ipc_path(path): with open(path): return True + # Returns on first IPC pipe matching Discord's def get_ipc_path(pipe=None): ipc = 'discord-ipc-'