From d64d2afe753297a57ae5594d4db6b28d527f82e2 Mon Sep 17 00:00:00 2001 From: ihmily <114978440+ihmily@users.noreply.github.com> Date: Fri, 13 Jun 2025 18:20:34 +0800 Subject: [PATCH] fix: improve message push judgment --- app/core/record_manager.py | 16 ++++++---------- app/core/stream_manager.py | 6 ++++-- app/messages/message_pusher.py | 33 +++++++++++++++++++-------------- app/ui/views/settings_view.py | 2 +- main.py | 2 +- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/core/record_manager.py b/app/core/record_manager.py index e5fc540..033b99b 100644 --- a/app/core/record_manager.py +++ b/app/core/record_manager.py @@ -262,7 +262,6 @@ class RecordingManager: stream_info.anchor_name = utils.clean_name(stream_info.anchor_name, self._["live_room"]) recording.is_live = stream_info.is_live - is_record = True if recording.is_live and not recording.is_recording: recording.status_info = RecordingStatus.PREPARING_RECORDING recording.live_title = stream_info.title @@ -273,7 +272,7 @@ class RecordingManager: msg_manager = MessagePusher(self.settings) user_config = self.settings.user_config - if MessagePusher.should_push_message(self.settings, recording): + if MessagePusher.should_push_message(self.settings, recording, message_type='start'): push_content = self._["push_content"] begin_push_message_text = user_config.get("custom_stream_start_content") if begin_push_message_text: @@ -288,17 +287,14 @@ class RecordingManager: self.app.page.run_task(msg_manager.push_messages, msg_title, push_content) - if user_config.get("only_notify_no_record"): - notify_loop_time = user_config.get("notify_loop_time") - recording.loop_time_seconds = int(notify_loop_time or 3600) - is_record = False - else: - recording.loop_time_seconds = self.loop_time_seconds - - if is_record: + if not user_config.get("only_notify_no_record"): + recording.loop_time_seconds = self.loop_time_seconds self.start_update(recording) self.app.page.run_task(recorder.start_recording, stream_info) else: + notify_loop_time = user_config.get("notify_loop_time") + recording.loop_time_seconds = int(notify_loop_time or 3600) + recording.status_info = RecordingStatus.NOT_RECORDING recording.is_checking = False self.app.page.run_task(self.app.record_card_manager.update_card, recording) diff --git a/app/core/stream_manager.py b/app/core/stream_manager.py index ca3ff83..f890dab 100644 --- a/app/core/stream_manager.py +++ b/app/core/stream_manager.py @@ -263,13 +263,13 @@ class LiveStreamRecorder: if not self.recording.is_recording: logger.success(f"Live recording has stopped: {record_name}") else: - self.recording.is_recording = False + logger.success(f"Live recording completed: {record_name}") msg_manager = MessagePusher(self.settings) user_config = self.settings.user_config if self.app.recording_enabled and MessagePusher.should_push_message( - self.settings, self.recording, check_manually_stopped=True): + self.settings, self.recording, check_manually_stopped=True, message_type='end'): push_content = self._["push_content_end"] end_push_message_text = user_config.get("custom_stream_end_content") if end_push_message_text: @@ -283,6 +283,8 @@ class LiveStreamRecorder: msg_title = msg_title or self._["status_notify"] self.app.page.run_task(msg_manager.push_messages, msg_title, push_content) + + self.recording.is_recording = False try: self.recording.update({"display_title": display_title}) await self.app.record_card_manager.update_card(self.recording) diff --git a/app/messages/message_pusher.py b/app/messages/message_pusher.py index 1e5c62a..37fd5e7 100644 --- a/app/messages/message_pusher.py +++ b/app/messages/message_pusher.py @@ -24,7 +24,7 @@ class MessagePusher: return any(self.settings.user_config.get(channel) for channel in push_channels) @staticmethod - def should_push_message(settings, recording, check_manually_stopped=False): + def should_push_message(settings, recording, check_manually_stopped=False, message_type=None): """ Check if message should be pushed """ @@ -32,18 +32,25 @@ class MessagePusher: return False user_config = settings.user_config + should_only_notify_no_record = user_config.get("only_notify_no_record") + is_stream_start_enabled = user_config.get("stream_start_notification_enabled") + is_stream_end_enabled = user_config.get("stream_end_notification_enabled") - # Check if global push settings are enabled - global_push_enabled = ( - user_config.get("stream_start_notification_enabled") or - user_config.get("stream_end_notification_enabled") or - user_config.get("only_notify_no_record") - ) - - if not global_push_enabled: + if message_type is None: + if hasattr(recording, 'is_recording') and recording.is_recording: + message_type = 'end' + else: + message_type = 'start' + + if message_type == 'start' and should_only_notify_no_record and is_stream_start_enabled: + return True + + if message_type == 'start' and not is_stream_start_enabled: return False - - # Check if any push platform is enabled + + if message_type == 'end' and not is_stream_end_enabled: + return False + push_channels = [ "dingtalk_enabled", "wechat_enabled", @@ -59,10 +66,8 @@ class MessagePusher: if not any_channel_enabled: return False - # Check if manually stopped status is needed - if check_manually_stopped and recording.manually_stopped: + if message_type == 'end' and check_manually_stopped and recording.manually_stopped: return False - return True async def push_messages(self, msg_title: str, push_content: str): diff --git a/app/ui/views/settings_view.py b/app/ui/views/settings_view.py index 733aecf..6bb01f1 100644 --- a/app/ui/views/settings_view.py +++ b/app/ui/views/settings_view.py @@ -1181,7 +1181,7 @@ class SettingsPage(PageBase): ) login_required_switch = ft.Switch( - value=self.get_config_value("login_required", True), + value=self.get_config_value("login_required", False), on_change=toggle_login_required, ) diff --git a/main.py b/main.py index 37ca289..3813204 100644 --- a/main.py +++ b/main.py @@ -133,7 +133,7 @@ async def main(page: ft.Page) -> None: app.auth_manager = auth_manager await auth_manager.initialize() - login_required = app.settings.get_config_value("login_required", True) + login_required = app.settings.get_config_value("login_required", False) if login_required: session_token = await page.client_storage.get_async("session_token")