@@ -511,11 +511,17 @@ export default class View {
511
511
} ) ;
512
512
513
513
const startBot = limitations => {
514
- const $runButtons = $ ( '#runButton, #summaryRunButton' ) ;
515
- const $stopButtons = $ ( '#stopButton, #summaryStopButton' ) ;
516
- $stopButtons . show ( ) ;
517
- $runButtons . hide ( ) ;
518
- $runButtons . prop ( 'disabled' , true ) ;
514
+ const el_run_buttons = document . querySelectorAll ( '#runButton, #summaryRunButton' ) ;
515
+ const el_stop_buttons = document . querySelectorAll ( '#stopButton, #summaryStopButton' ) ;
516
+
517
+ el_run_buttons . forEach ( el_run_button => {
518
+ el_run_button . style . display = 'none' ;
519
+ el_run_button . setAttributeNode ( document . createAttribute ( 'disabled' ) ) ;
520
+ } ) ;
521
+ el_stop_buttons . forEach ( el_stop_button => {
522
+ el_stop_button . style . display = 'initial' ;
523
+ } ) ;
524
+
519
525
globalObserver . emit ( 'summary.disable_clear' ) ;
520
526
showSummary ( ) ;
521
527
this . blockly . run ( limitations ) ;
@@ -627,31 +633,47 @@ export default class View {
627
633
this . blockly . stop ( ) ;
628
634
}
629
635
addEventHandlers ( ) {
636
+ const getRunButtonElements = ( ) => document . querySelectorAll ( '#runButton, #summaryRunButton' ) ;
637
+ const getStopButtonElements = ( ) => document . querySelectorAll ( '#stopButton, #summaryStopButton' ) ;
638
+
630
639
window . addEventListener ( 'storage' , e => {
631
640
window . onbeforeunload = null ;
632
641
if ( e . key === 'activeToken' && ! e . newValue ) window . location . reload ( ) ;
633
642
if ( e . key === 'realityCheckTime' ) hideRealityCheck ( ) ;
634
643
} ) ;
635
644
636
645
globalObserver . register ( 'Error' , error => {
637
- $ ( '#runButton, #summaryRunButton' ) . prop ( 'disabled' , false ) ;
646
+ getRunButtonElements ( ) . forEach ( el_run_button => el_run_button . removeAttribute ( 'disabled' ) ) ;
647
+
638
648
if ( error . error && error . error . error . code === 'InvalidToken' ) {
639
649
removeAllTokens ( ) ;
640
650
updateTokenList ( ) ;
641
651
this . stop ( ) ;
642
652
}
643
653
} ) ;
644
654
655
+ globalObserver . register ( 'bot.running' , ( ) => {
656
+ getRunButtonElements ( ) . forEach ( el_run_button => {
657
+ el_run_button . style . display = 'none' ;
658
+ el_run_button . setAttributeNode ( document . createAttribute ( 'disabled' ) ) ;
659
+ } ) ;
660
+ getStopButtonElements ( ) . forEach ( el_stop_button => {
661
+ el_stop_button . style . display = 'inline-block' ;
662
+ el_stop_button . removeAttribute ( 'disabled' ) ;
663
+ } ) ;
664
+ } ) ;
665
+
645
666
globalObserver . register ( 'bot.stop' , ( ) => {
646
- const $runButtons = $ ( '#runButton, #summaryRunButton' ) ;
647
- const $stopButtons = $ ( '#stopButton, #summaryStopButton' ) ;
648
- if ( $runButtons . is ( ':visible' ) || $stopButtons . is ( ':visible' ) ) {
649
- $runButtons . show ( ) ;
650
- $stopButtons . hide ( ) ;
651
-
652
- $stopButtons . prop ( 'disabled' , false ) ;
653
- $runButtons . prop ( 'disabled' , false ) ;
654
- }
667
+ // Enable run button, this event is emitted after the interpreter
668
+ // killed the API connection.
669
+ getStopButtonElements ( ) . forEach ( el_stop_button => {
670
+ el_stop_button . style . display = 'none' ;
671
+ el_stop_button . removeAttribute ( 'disabled' ) ;
672
+ } ) ;
673
+ getRunButtonElements ( ) . forEach ( el_run_button => {
674
+ el_run_button . style . display = null ;
675
+ el_run_button . removeAttribute ( 'disabled' ) ;
676
+ } ) ;
655
677
} ) ;
656
678
657
679
globalObserver . register ( 'bot.info' , info => {
0 commit comments