From 594cc561cb17bb03d4f32b79ccda123ecdaf9b45 Mon Sep 17 00:00:00 2001 From: evilbeast Date: Sat, 27 Aug 2022 14:28:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=AE=E4=BF=A1=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E9=80=80=E5=87=BA=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ntchat/const/notify_type.py | 3 +++ ntchat/core/mgr.py | 6 ++---- ntchat/core/wechat.py | 9 +++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ntchat/const/notify_type.py b/ntchat/const/notify_type.py index 0d321b0..7220f38 100644 --- a/ntchat/const/notify_type.py +++ b/ntchat/const/notify_type.py @@ -1,6 +1,9 @@ # 用于接收所有的通知消息 MT_ALL = 11000 +# 微信进程退出通知 +MT_RECV_WECHAT_QUIT_MSG = 11001 + # 第个通知消息,此时已经托管上微信 MT_READY_MSG = 11024 diff --git a/ntchat/core/mgr.py b/ntchat/core/mgr.py index 192de18..4a7a943 100644 --- a/ntchat/core/mgr.py +++ b/ntchat/core/mgr.py @@ -49,8 +49,7 @@ class WeChatMgr(metaclass=Singleton): if client_id not in self.__instance_map: for instance in self.__instance_list: if instance.pid == pid: - instance.client_id = client_id - instance.status = True + instance.bind_client_id(client_id) self.__instance_map[client_id] = instance bind_instance = instance break @@ -71,5 +70,4 @@ class WeChatMgr(metaclass=Singleton): def __on_close(self, client_id): log.debug("close client_id: %d", client_id) if client_id in self.__instance_map: - self.__instance_map[client_id].login_status = False - self.__instance_map[client_id].status = False + self.__instance_map[client_id].on_close() diff --git a/ntchat/core/wechat.py b/ntchat/core/wechat.py index c9ebfa9..a2445b8 100644 --- a/ntchat/core/wechat.py +++ b/ntchat/core/wechat.py @@ -68,6 +68,15 @@ class WeChat: return f return wrapper + def on_close(self): + self.login_status = False + self.status = False + self.__msg_event_emitter.emit(str(notify_type.MT_RECV_WECHAT_QUIT_MSG), self) + + def bind_client_id(self, client_id): + self.status = True + self.client_id = client_id + def on_recv(self, message): log.debug("on recv message: %s", message) msg_type = message["type"]