File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1- import { onBeforeMount , ref } from 'vue' ;
1+ import { onBeforeMount , onBeforeUnmount , ref } from 'vue' ;
2+ import { StimulusDevToolsMessage } from '@/types' ;
3+ import { MessageEventName , MessageType } from '@/enum' ;
24
35const stimulusDetected = ref ( false ) ;
46
@@ -8,9 +10,20 @@ function checkIfHasStimulus() {
810 } ) ;
911}
1012
13+ function onRuntimeMessage ( message : StimulusDevToolsMessage ) {
14+ if ( message . type === MessageType . Event && message . name === MessageEventName . Undetected ) {
15+ checkIfHasStimulus ( ) ;
16+ }
17+ }
18+
1119export const useStimulusDetector = ( ) => {
1220 onBeforeMount ( ( ) => {
1321 if ( ! stimulusDetected . value ) checkIfHasStimulus ( ) ;
22+ chrome . runtime . onMessage . addListener ( onRuntimeMessage ) ;
23+ } ) ;
24+
25+ onBeforeUnmount ( ( ) => {
26+ chrome . runtime . onMessage . removeListener ( onRuntimeMessage ) ;
1427 } ) ;
1528
1629 return { stimulusDetected, checkIfHasStimulus } ;
Original file line number Diff line number Diff line change 2020 return ;
2121 }
2222
23+ if ( detector . retry < 8 ) {
24+ window . postMessage (
25+ {
26+ type : 'stimulus-devtools:event' ,
27+ name : 'stimulus-devtools:undetected' ,
28+ } ,
29+ '*' ,
30+ ) ;
31+ if ( window [ '__STIMULUS_DEVTOOLS_DETECTED__' ] ) delete window [ '__STIMULUS_DEVTOOLS_DETECTED__' ] ;
32+ }
33+
2334 if ( detector . retry > 0 ) {
2435 detector . retry -- ;
2536 setTimeout ( ( ) => {
You can’t perform that action at this time.
0 commit comments