4646 get_text_color ,
4747)
4848from fastflix .shared import error_message , message , time_to_number , yes_no_message , clean_file_string
49- from fastflix .windows_tools import show_windows_notification
49+ from fastflix .windows_tools import show_windows_notification , prevent_sleep_mode , allow_sleep_mode
5050from fastflix .widgets .background_tasks import ThumbnailCreator
5151from fastflix .widgets .progress_bar import ProgressBar , Task
5252from fastflix .widgets .video_options import VideoOptions
@@ -1825,6 +1825,7 @@ def encode_video(self):
18251825 logger .debug (t ("Starting conversion process" ))
18261826
18271827 self .app .fastflix .currently_encoding = True
1828+ prevent_sleep_mode ()
18281829 self .set_convert_button (False )
18291830 self .send_video_request_to_worker_queue (video_to_send )
18301831 self .disable_all ()
@@ -1870,6 +1871,7 @@ def add_to_queue(self):
18701871 # @reusables.log_exception("fastflix", show_traceback=False)
18711872 def conversion_complete (self , success : bool ):
18721873 self .paused = False
1874+ allow_sleep_mode ()
18731875 self .set_convert_button ()
18741876
18751877 if not success :
@@ -1890,6 +1892,7 @@ def conversion_complete(self, success: bool):
18901892 def conversion_cancelled (self , video : Video ):
18911893 self .app .fastflix .worker_queue .put (Request ("cancel" ))
18921894 self .app .fastflix .currently_encoding = False
1895+ allow_sleep_mode ()
18931896 self .set_convert_button ()
18941897
18951898 exists = video .video_settings .output_path .exists ()
@@ -1952,14 +1955,18 @@ def status_update(self, status_response):
19521955 video_to_send : Optional [Video ] = None
19531956 errored = False
19541957 same_video = False
1958+
19551959 for video in self .app .fastflix .conversion_list :
19561960 if response .video_uuid == video .uuid :
19571961 video .status .running = False
1962+
19581963 if response .status == "cancelled" :
19591964 video .status .cancelled = True
19601965 self .app .fastflix .currently_encoding = False
1966+ allow_sleep_mode ()
19611967 self .video_options .update_queue ()
19621968 return
1969+
19631970 if response .status == "complete" :
19641971 video .status .current_command += 1
19651972 if len (video .video_settings .conversion_commands ) > video .status .current_command :
@@ -1968,15 +1975,15 @@ def status_update(self, status_response):
19681975 break
19691976 else :
19701977 video .status .complete = True
1978+
19711979 if response .status == "error" :
19721980 video .status .error = True
19731981 errored = True
19741982 break
19751983
19761984 if errored and not self .video_options .queue .ignore_errors .isChecked ():
1977- self .app .fastflix .currently_encoding = False
19781985 self .conversion_complete (success = False )
1979- self .video_options . update_queue ()
1986+ self .end_encoding ()
19801987 return
19811988
19821989 if not video_to_send :
@@ -1987,32 +1994,37 @@ def status_update(self, status_response):
19871994 break
19881995
19891996 if not video_to_send :
1990- self .app .fastflix .currently_encoding = False
19911997 self .conversion_complete (success = True )
1992- self .video_options . update_queue ()
1998+ self .end_encoding ()
19931999 return
19942000
19952001 self .app .fastflix .currently_encoding = True
19962002 if not same_video and self .app .fastflix .conversion_paused :
1997- self .app .fastflix .currently_encoding = False
1998- self .video_options .update_queue ()
1999- return
2003+ return self .end_encoding ()
20002004
20012005 self .send_video_request_to_worker_queue (video_to_send )
20022006
2007+ def end_encoding (self ):
2008+ self .app .fastflix .currently_encoding = False
2009+ allow_sleep_mode ()
2010+ self .video_options .queue .run_after_done ()
2011+ self .video_options .update_queue ()
2012+
20032013 def send_next_video (self ) -> bool :
20042014 if not self .app .fastflix .currently_encoding :
20052015 for video in self .app .fastflix .conversion_list :
20062016 if video .status .ready :
20072017 video .status .running = True
20082018 self .send_video_request_to_worker_queue (video )
20092019 self .app .fastflix .currently_encoding = True
2020+ prevent_sleep_mode ()
20102021 return True
20112022 return False
20122023
20132024 def send_video_request_to_worker_queue (self , video : Video ):
20142025 command = video .video_settings .conversion_commands [video .status .current_command ]
20152026 self .app .fastflix .currently_encoding = True
2027+ prevent_sleep_mode ()
20162028
20172029 # logger.info(f"Sending video {video.uuid} command {command.uuid} called from {inspect.stack()}")
20182030
0 commit comments