@@ -377,11 +377,21 @@ func getVideoDevices() map[int]string {
377377 return deviceMap
378378}
379379
380- func stopAppWithCmd (ctx context.Context , app app.ArduinoApp , cmd string ) iter.Seq [StreamMessage ] {
380+ func stopAppWithCmd (ctx context.Context , docker command. Cli , app app.ArduinoApp , cmd string ) iter.Seq [StreamMessage ] {
381381 return func (yield func (StreamMessage ) bool ) {
382382 ctx , cancel := context .WithCancel (ctx )
383383 defer cancel ()
384384
385+ appStatus , err := getAppStatus (ctx , docker , app )
386+ if err != nil {
387+ yield (StreamMessage {error : err })
388+ return
389+ }
390+ if appStatus .Status != StatusStarting && appStatus .Status != StatusRunning {
391+ yield (StreamMessage {error : fmt .Errorf ("App %q is not running" , app .Name )})
392+ return
393+ }
394+
385395 if ! yield (StreamMessage {data : fmt .Sprintf ("Stopping app %q" , app .Name )}) {
386396 return
387397 }
@@ -395,6 +405,8 @@ func stopAppWithCmd(ctx context.Context, app app.ArduinoApp, cmd string) iter.Se
395405 return
396406 }
397407 })
408+
409+ fmt .Printf ("this is the main sketch path:%s" , app .MainSketchPath )
398410 if app .MainSketchPath != nil {
399411 // TODO: check that the app sketch is running before attempting to stop it.
400412
@@ -425,12 +437,12 @@ func stopAppWithCmd(ctx context.Context, app app.ArduinoApp, cmd string) iter.Se
425437 }
426438}
427439
428- func StopApp (ctx context.Context , app app.ArduinoApp ) iter.Seq [StreamMessage ] {
429- return stopAppWithCmd (ctx , app , "stop" )
440+ func StopApp (ctx context.Context , dockerClient command. Cli , app app.ArduinoApp ) iter.Seq [StreamMessage ] {
441+ return stopAppWithCmd (ctx , dockerClient , app , "stop" )
430442}
431443
432- func StopAndDestroyApp (ctx context.Context , app app.ArduinoApp ) iter.Seq [StreamMessage ] {
433- return stopAppWithCmd (ctx , app , "down" )
444+ func StopAndDestroyApp (ctx context.Context , dockerClient command. Cli , app app.ArduinoApp ) iter.Seq [StreamMessage ] {
445+ return stopAppWithCmd (ctx , dockerClient , app , "down" )
434446}
435447
436448func RestartApp (
@@ -458,7 +470,7 @@ func RestartApp(
458470 return
459471 }
460472
461- stopStream := StopApp (ctx , * runningApp )
473+ stopStream := StopApp (ctx , docker , * runningApp )
462474 for msg := range stopStream {
463475 if ! yield (msg ) {
464476 return
@@ -888,8 +900,8 @@ func CloneApp(
888900 return CloneAppResponse {ID : id }, nil
889901}
890902
891- func DeleteApp (ctx context.Context , app app.ArduinoApp ) error {
892- for msg := range StopApp (ctx , app ) {
903+ func DeleteApp (ctx context.Context , dockerClient command. Cli , app app.ArduinoApp ) error {
904+ for msg := range StopApp (ctx , dockerClient , app ) {
893905 if msg .error != nil {
894906 return fmt .Errorf ("failed to stop app: %w" , msg .error )
895907 }
0 commit comments