@@ -511,11 +511,19 @@ export default class View {
511511 } ) ;
512512
513513 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 elRunButtons = document . querySelectorAll ( '#runButton, #summaryRunButton' ) ;
515+ const elStopButtons = document . querySelectorAll ( '#stopButton, #summaryStopButton' ) ;
516+
517+ elRunButtons . forEach ( el => {
518+ const elRunButton = el ;
519+ elRunButton . style . display = 'none' ;
520+ elRunButton . setAttributeNode ( document . createAttribute ( 'disabled' ) ) ;
521+ } ) ;
522+ elStopButtons . forEach ( el => {
523+ const elStopButton = el ;
524+ elStopButton . style . display = 'inline-block' ;
525+ } ) ;
526+
519527 globalObserver . emit ( 'summary.disable_clear' ) ;
520528 showSummary ( ) ;
521529 this . blockly . run ( limitations ) ;
@@ -627,31 +635,54 @@ export default class View {
627635 this . blockly . stop ( ) ;
628636 }
629637 addEventHandlers ( ) {
638+ const getRunButtonElements = ( ) => document . querySelectorAll ( '#runButton, #summaryRunButton' ) ;
639+ const getStopButtonElements = ( ) => document . querySelectorAll ( '#stopButton, #summaryStopButton' ) ;
640+
630641 window . addEventListener ( 'storage' , e => {
631642 window . onbeforeunload = null ;
632643 if ( e . key === 'activeToken' && ! e . newValue ) window . location . reload ( ) ;
633644 if ( e . key === 'realityCheckTime' ) hideRealityCheck ( ) ;
634645 } ) ;
635646
636647 globalObserver . register ( 'Error' , error => {
637- $ ( '#runButton, #summaryRunButton' ) . prop ( 'disabled' , false ) ;
648+ getRunButtonElements ( ) . forEach ( el => {
649+ const elRunButton = el ;
650+ elRunButton . removeAttribute ( 'disabled' ) ;
651+ } ) ;
652+
638653 if ( error . error && error . error . error . code === 'InvalidToken' ) {
639654 removeAllTokens ( ) ;
640655 updateTokenList ( ) ;
641656 this . stop ( ) ;
642657 }
643658 } ) ;
644659
660+ globalObserver . register ( 'bot.running' , ( ) => {
661+ getRunButtonElements ( ) . forEach ( el => {
662+ const elRunButton = el ;
663+ elRunButton . style . display = 'none' ;
664+ elRunButton . setAttributeNode ( document . createAttribute ( 'disabled' ) ) ;
665+ } ) ;
666+ getStopButtonElements ( ) . forEach ( el => {
667+ const elStopButton = el ;
668+ elStopButton . style . display = 'inline-block' ;
669+ elStopButton . removeAttribute ( 'disabled' ) ;
670+ } ) ;
671+ } ) ;
672+
645673 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- }
674+ // Enable run button, this event is emitted after the interpreter
675+ // killed the API connection.
676+ getStopButtonElements ( ) . forEach ( el => {
677+ const elStopButton = el ;
678+ elStopButton . style . display = null ;
679+ elStopButton . removeAttribute ( 'disabled' ) ;
680+ } ) ;
681+ getRunButtonElements ( ) . forEach ( el => {
682+ const elRunButton = el ;
683+ elRunButton . style . display = null ;
684+ elRunButton . removeAttribute ( 'disabled' ) ;
685+ } ) ;
655686 } ) ;
656687
657688 globalObserver . register ( 'bot.info' , info => {
0 commit comments