Philipp Hörist pushed to branch master at gajim / gajim


Commits:
f8edd66b by mesonium at 2024-10-02T10:56:34+00:00
fix: Voice Message: Handle error when temp folder is not available

- - - - -


2 changed files:

- gajim/gtk/voice_message_recorder.py
- gajim/gtk/voice_message_recorder_widget.py


Changes:

=====================================
gajim/gtk/voice_message_recorder.py
=====================================
@@ -186,6 +186,10 @@ def start_recording(self) -> None:
             self._file_name = f'voice-message-{timestamp}.{self._filetype}'
             self._file_path = configpaths.get_temp_dir() / self._file_name
 
+        if not self._file_path.parent.exists():
+            self._handle_error_output_dir_inaccessible()
+            return
+
         self._output_file_counter += 1
         self._filesink.set_property(
             'location', f'{self._file_path}.part{self._output_file_counter}'
@@ -342,9 +346,20 @@ def _handle_error_on_stop(self, message: Gst.Message | 
None) -> None:
     def _handle_error_on_merging(self, message: Gst.Message | None) -> None:
         if message is not None and not self._is_error(message):
             return
-        # TODO
+
+        self._error_callback(
+            GST_ERROR_ON_MERGING,
+            _('Error while merging recordings, please try again.')
+        )
         log.debug('Error when merging the recordings!')
 
+    def _handle_error_output_dir_inaccessible(self) -> None:
+        log.error('Voice message lost. Temporary output folder %s '
+                  'not accessible', self._file_path.parent)
+        error_message = _('Voice message could not be saved. Please try 
again.')
+        self._error_callback(GST_ERROR_ON_MERGING, error_message)
+        self.stop_and_reset()
+
     def _custom_message(self, name: str) -> None:
         custom_structure = Gst.Structure.new_empty(name)
         custom_message = Gst.Message.new_application(None, custom_structure)
@@ -470,6 +485,10 @@ def _merge_opus_m4a_command(self) -> str:
         return command
 
     def _merge_output_files(self) -> None:
+        if not self._file_path.parent.exists():
+            self._handle_error_output_dir_inaccessible()
+            return
+
         command = self._merge_opus_m4a_command()
         pipeline = Gst.parse_launch(command)
 


=====================================
gajim/gtk/voice_message_recorder_widget.py
=====================================
@@ -229,8 +229,7 @@ def _on_error_occurred(self, occasion: int, error_msg: str) 
-> None:
                 self._stop_and_reset_recording()
             else:
                 self._stop_recording()
-
-        if occasion == GST_ERROR_ON_RECORDING:
+        elif occasion == GST_ERROR_ON_RECORDING:
             self._stop_recording()
 
             if not self._voice_message_recorder.audio_file_is_valid:
@@ -240,6 +239,8 @@ def _on_error_occurred(self, occasion: int, error_msg: str) 
-> None:
                     Path(self._voice_message_recorder.audio_file_abspath)
                 )
                 self._show_playback_box()
+        else:
+            self._stop_and_reset_recording()
 
     def _update_time_label(self, recording_time: Callable[..., int]) -> bool:
         formatted = format_duration(recording_time(), recording_time())
@@ -298,6 +299,8 @@ def _hide_error_message(self) -> None:
         self._ui.error_label.set_visible(False)
 
     def _on_record_toggle_clicked(self, _button: Gtk.Button) -> None:
+        self._hide_error_message()
+
         if self._voice_message_recorder.recording_in_progress:
             self._stop_recording()
 



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f8edd66b428dff3bf4c9fabaea3106bbaf9aada3

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/f8edd66b428dff3bf4c9fabaea3106bbaf9aada3
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to