@@ -26,10 +26,13 @@ package animatedledstrip.server
2626import animatedledstrip.animationutils.Animation
2727import animatedledstrip.animationutils.AnimationData
2828import animatedledstrip.leds.AnimatedLEDStrip
29- import kotlinx.coroutines.GlobalScope
30- import kotlinx.coroutines.Job
31- import kotlinx.coroutines.launch
29+ import kotlinx.coroutines.*
3230import org.tinylog.Logger
31+ import java.io.File
32+ import java.io.FileOutputStream
33+ import java.io.ObjectOutputStream
34+ import java.nio.file.Files
35+ import java.nio.file.Paths
3336
3437/* *
3538 * Class for running an animation that repeats until stopped.
@@ -52,6 +55,8 @@ internal class ContinuousRunAnimation(
5255
5356 private var job: Job ? = null
5457
58+ private val fileName = " $id .anim"
59+
5560
5661 init {
5762 sendStartAnimation() // Send animation to GUI
@@ -63,6 +68,14 @@ internal class ContinuousRunAnimation(
6368 */
6469 fun runAnimation () {
6570 job = GlobalScope .launch(handler.animationThreadPool) {
71+ launch {
72+ withContext(Dispatchers .IO ) {
73+ ObjectOutputStream (FileOutputStream (" .animations/$fileName " )).apply {
74+ writeObject(params)
75+ close()
76+ }
77+ }
78+ }
6679 Logger .trace { " params: $params " }
6780 while (continueAnimation) leds.run (params)
6881 sendEndAnimation()
@@ -78,6 +91,8 @@ internal class ContinuousRunAnimation(
7891 Logger .debug { " Animation $id ending" }
7992 if (continueAnimation) continueAnimation = false
8093 else job?.cancel()
94+ if (File (" .animations/$id " ).exists())
95+ Files .delete(Paths .get(" .animations/$fileName " ))
8196 }
8297
8398
0 commit comments