@@ -69,6 +69,7 @@ import io.github.vikulin.opengammakit.view.FwhmSpectrumSelectionDialogFragment
6969import io.github.vikulin.opengammakit.view.SaveSelectedSpectrumDialogFragment
7070import io.github.vikulin.opengammakit.view.SaveSpectrumDataIntoFileDialogFragment
7171import io.github.vikulin.opengammakit.view.SpectrumFileChooserDialogFragment
72+ import kotlinx.coroutines.Job
7273import kotlin.math.log10
7374
7475class SpectrumFragment : SerialConnectionFragment (),
@@ -298,6 +299,12 @@ class SpectrumFragment : SerialConnectionFragment(),
298299 val errorDialog = ErrorDialogFragment .Companion .newInstance(error)
299300 errorDialog.show(childFragmentManager, " error_dialog_fragment" )
300301 }? : run {
302+ if (progressJob?.isActive == true ){
303+ val error = " Spectrum recording is in progress"
304+ val errorDialog = ErrorDialogFragment .Companion .newInstance(error)
305+ errorDialog.show(childFragmentManager, " error_dialog_fragment" )
306+ return @run
307+ }
301308 val spectrumRecordingTimeDialog =
302309 SpectrumRecordingTimeDialogFragment .newInstance(60 )
303310 spectrumRecordingTimeDialog.show(childFragmentManager, " spectrum_recording_time" )
@@ -1446,6 +1453,8 @@ class SpectrumFragment : SerialConnectionFragment(),
14461453 measureTimer.stop()
14471454 }
14481455
1456+ private var progressJob: Job ? = null
1457+
14491458 override fun onSpectrumRecordingTime (time : Long ) {
14501459 measureMode = SpectrumMeasureMode .Scheduled
14511460 view?.keepScreenOn = true
@@ -1463,7 +1472,7 @@ class SpectrumFragment : SerialConnectionFragment(),
14631472 // Start tracking progress separately
14641473 startProgressUpdate(time)
14651474
1466- lifecycleScope.launch {
1475+ progressJob = lifecycleScope.launch {
14671476
14681477 delay(time * 1000L + 200L ) // Wait for recording time (handled by coroutine)
14691478 // After recording ends
0 commit comments