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"]