From a7932adfe4dd380d06e6ecbd3a83907e5a67d862 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 10 May 2024 12:48:39 +0100 Subject: [PATCH] Add more protection against hitting return twice --- app/config.py | 1 + app/musicmuster.py | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/config.py b/app/config.py index 1d94487..48f4706 100644 --- a/app/config.py +++ b/app/config.py @@ -78,6 +78,7 @@ class Config(object): OBS_HOST = "localhost" OBS_PASSWORD = "auster" OBS_PORT = 4455 + PLAY_NEXT_GUARD_MS = 10000 PLAY_SETTLE = 500000 REPLACE_FILES_DEFAULT_SOURCE = "/home/kae/music/Singles/tmp" RETURN_KEY_DEBOUNCE_MS = 500 diff --git a/app/musicmuster.py b/app/musicmuster.py index 04d5db6..310378f 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1164,10 +1164,21 @@ class Window(QMainWindow, Ui_MainWindow): > dt.datetime.now() ): return + # If return is pressed during first PLAY_NEXT_GUARD_MS then + # default to NOT playing the next track, else default to + # playing it. + default_yes: bool = ( + track_sequence.now.start_time is not None + and ( + (dt.datetime.now() - track_sequence.now.start_time).total_seconds() + * 1000 + > Config.PLAY_NEXT_GUARD_MS + ) + ) if not helpers.ask_yes_no( "Track playing", "Really play next track now?", - default_yes=True, + default_yes=default_yes, parent=self, ): return @@ -1311,7 +1322,9 @@ class Window(QMainWindow, Ui_MainWindow): if os.path.exists(rf.obsolete_path): os.unlink(rf.obsolete_path) else: - log.error(f"replace_files: could not unlink {rf.obsolete_path=}") + log.error( + f"replace_files: could not unlink {rf.obsolete_path=}" + ) continue if rf.track_path: if os.path.exists(rf.track_path): @@ -1340,12 +1353,12 @@ class Window(QMainWindow, Ui_MainWindow): else: # We're importing a new track do_import = self.ok_to_import( - session, - os.path.basename(rf.new_file_path), - rf.tags + session, os.path.basename(rf.new_file_path), rf.tags ) if do_import: - rf.audio_metadata = helpers.get_audio_metadata(rf.new_file_path) + rf.audio_metadata = helpers.get_audio_metadata( + rf.new_file_path + ) import_files.append(rf) # self.import_filenames(dlg.replacement_files)