Add more protection against hitting return twice

This commit is contained in:
Keith Edmunds 2024-05-10 12:48:39 +01:00
parent f825304de4
commit a7932adfe4
2 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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)