Skip to content

Commit 5936cc7

Browse files
committed
Integrate license status caching in UI context. Updated App.js to set cached license status during initialization, enhancing license management. Refactored gate.js to clarify license status handling and improve logging context for better debugging.
1 parent a378f22 commit 5936cc7

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'src/ui/FigmaUI.css'
55
import Tracking from 'src/utils/Tracking'
66
import Router from 'src/utils/Router'
77
import Element from 'src/ui/Element'
8+
import { setCachedLicenseStatus } from 'src/payments/gate'
89

910
import 'src/ui/components/toolbar/ToolbarComponent'
1011
import 'src/ui/views/form/FormView'
@@ -21,6 +22,10 @@ class ui extends Element {
2122
if (msg.type == 'init-hidden' || msg.type == 'init' || msg.type == 'init-direct') {
2223
this.data.preferences = msg.preferences
2324
this.data.license = msg.license
25+
26+
// Update UI context license cache (separate from Core.js context)
27+
setCachedLicenseStatus(msg.license)
28+
2429
Tracking.setup(WP_AMPLITUDE_KEY, msg.UUID)
2530
Tracking.track('openPlugin', { cmd: msg.cmd })
2631
}

src/payments/gate.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// License gate - Now checks actual stored license
2-
// Global license state loaded on plugin init
1+
// License gate - Manages license status in current JavaScript context
2+
// Note: Core.js (main thread) and UI (iframe) have separate instances of this cache
33
let cachedLicenseStatus = null
44

55
function getRandomIntInclusive(min, max) {
@@ -9,13 +9,15 @@ function getRandomIntInclusive(min, max) {
99

1010
export function setCachedLicenseStatus(license) {
1111
cachedLicenseStatus = license
12-
console.log('[Gate] License status updated:', license ? 'LICENSED' : 'UNLICENSED')
12+
const context = typeof figma !== 'undefined' ? 'Core' : 'UI'
13+
console.log(`[Gate:${context}] License status updated:`, license ? 'LICENSED' : 'UNLICENSED')
1314
}
1415

1516
export function shouldShowCountdown() {
16-
// Check actual license status
17+
// Check actual license status in current context
1718
const isLicensed = cachedLicenseStatus && cachedLicenseStatus.licensed
18-
console.log('[Gate] shouldShowCountdown:', !isLicensed, 'cached license:', cachedLicenseStatus)
19+
const context = typeof figma !== 'undefined' ? 'Core' : 'UI'
20+
console.log(`[Gate:${context}] shouldShowCountdown:`, !isLicensed, 'cached license:', cachedLicenseStatus)
1921
return !isLicensed
2022
}
2123

0 commit comments

Comments
 (0)