@@ -12,6 +12,18 @@ export default defineUnlistedScript(async () => {
1212 const FIGMA_READY_TIMEOUT = 1000
1313 const FIGMA_RECOVER_INTERVAL = 3000
1414
15+ let announcedUnavailable = false
16+
17+ const announceUnavailable = ( ) => {
18+ if ( announcedUnavailable ) return
19+ if ( document . visibilityState === 'hidden' ) return
20+ runtimeMode . value = 'unavailable'
21+ announcedUnavailable = true
22+ console . log (
23+ '[tempad-dev] `window.figma` is not available. TemPad Dev is currently unavailable.'
24+ )
25+ }
26+
1527 async function ensureFigmaReady ( timeout ?: number ) : Promise < boolean > {
1628 try {
1729 await waitFor ( ( ) => window . figma ?. currentPage != null , timeout ? { timeout } : undefined )
@@ -24,10 +36,7 @@ export default defineUnlistedScript(async () => {
2436 await waitFor ( ( ) => getCanvas ( ) != null && getLeftPanel ( ) != null )
2537 const ready = await ensureFigmaReady ( FIGMA_READY_TIMEOUT )
2638 if ( ! ready ) {
27- runtimeMode . value = 'unavailable'
28- console . log (
29- '[tempad-dev] `window.figma` is not available. TemPad Dev is currently unavailable.'
30- )
39+ announceUnavailable ( )
3140 const panelEl = ( ) => document . getElementById ( 'tempad' )
3241
3342 const tryRecover = async ( ) => {
@@ -40,6 +49,7 @@ export default defineUnlistedScript(async () => {
4049 return true
4150 }
4251 if ( el && document . visibilityState === 'hidden' ) el . style . display = 'none'
52+ else announceUnavailable ( )
4353 return false
4454 }
4555
@@ -56,7 +66,8 @@ export default defineUnlistedScript(async () => {
5666 return
5767 }
5868 el . style . display = ''
59- await tryRecover ( )
69+ const ok = await tryRecover ( )
70+ if ( ! ok ) announceUnavailable ( )
6071 }
6172
6273 const handleFocus = async ( ) => {
0 commit comments