Browse Source

fix(test-app): move native fetcher configuration to HomeView

Move native fetcher configuration from App.vue mounted() to HomeView.vue
onMounted() because App.vue's mounted hook was not executing reliably,
likely due to Vue router lifecycle timing.

Changes:
- App.vue: Remove non-executing configuration code, add note explaining move
- HomeView.vue: Add configureNativeFetcher() function with full configuration
  flow including ES256K JWT generation, API URL setup, and starred plans update
- Add nativeFetcherConfigured ref to prevent duplicate configuration attempts
- Wrap starred plans update in try-catch (non-blocking if it fails)

This fixes the issue where TestNativeFetcher was not being configured,
causing all prefetch operations to fail with "Not configured" error and
fall back to emergency content.

Verified: Configuration now executes successfully on HomeView mount,
TestNativeFetcher shows "Configured with API" in logcat.
master
Matthew Raymer 1 day ago
parent
commit
5272cc0912
  1. 81
      test-apps/daily-notification-test/src/App.vue
  2. 104
      test-apps/daily-notification-test/src/views/HomeView.vue

81
test-apps/daily-notification-test/src/App.vue

@ -36,10 +36,7 @@
<script lang="ts">
import { Vue, Component, toNative } from 'vue-facing-decorator'
import { Capacitor } from '@capacitor/core'
import { DailyNotification } from '@timesafari/daily-notification-plugin'
import { TEST_USER_ZERO_CONFIG, generateEndorserJWT } from './config/test-user-zero'
import { logger } from './lib/logger'
// NOTE: Native fetcher configuration imports removed - moved to HomeView.vue
@Component
class App extends Vue {
@ -47,77 +44,11 @@ class App extends Vue {
errorMessage = ''
async mounted() {
// CRITICAL: Log immediately to verify this hook executes
console.log('🚀 App.vue: mounted() hook EXECUTING')
console.log('🚀 App.vue: Capacitor.isNativePlatform() =', Capacitor.isNativePlatform())
// Configure native fetcher on native platforms (Android/iOS)
if (Capacitor.isNativePlatform()) {
console.log('🚀 App.vue: Entering native platform configuration block')
try {
// Use console.log for visibility in adb logcat
console.log('🔧 App.vue: Starting native fetcher configuration...')
logger.info('Configuring native fetcher...')
// Get API server URL first (before JWT generation)
const apiBaseUrl = TEST_USER_ZERO_CONFIG.getApiServerUrl()
console.log('🔧 App.vue: API Base URL:', apiBaseUrl)
console.log('🔧 App.vue: Server Mode:', TEST_USER_ZERO_CONFIG.api.serverMode)
// Skip configuration if in mock mode (no real API calls)
if (TEST_USER_ZERO_CONFIG.api.serverMode === 'mock') {
console.log('⏭️ App.vue: Mock mode - skipping configuration')
logger.warn('Mock mode enabled - native fetcher will not be configured')
return
}
console.log('🔧 App.vue: Generating JWT token...')
// Generate JWT token for authentication
const jwtToken = await generateEndorserJWT()
console.log('✅ App.vue: JWT token generated, length:', jwtToken.length)
console.log('🔧 App.vue: Calling configureNativeFetcher with:', {
apiBaseUrl,
activeDid: TEST_USER_ZERO_CONFIG.identity.did.substring(0, 30) + '...',
jwtTokenLength: jwtToken.length
})
// Configure native fetcher with credentials
await DailyNotification.configureNativeFetcher({
apiBaseUrl: apiBaseUrl,
activeDid: TEST_USER_ZERO_CONFIG.identity.did,
jwtToken: jwtToken
})
console.log('✅ App.vue: Native fetcher configured successfully!')
logger.info('Native fetcher configured successfully', {
apiBaseUrl: apiBaseUrl.substring(0, 50) + '...',
activeDid: TEST_USER_ZERO_CONFIG.identity.did.substring(0, 30) + '...'
})
// Update starred plan IDs from config so native fetcher can use them
console.log('🔧 App.vue: Updating starred plan IDs...')
const planIds = [...TEST_USER_ZERO_CONFIG.starredProjects.planIds]
console.log('🔧 App.vue: Plan IDs to update:', planIds.length, 'plans')
const updateResult = await DailyNotification.updateStarredPlans({
planIds: planIds
})
console.log('✅ App.vue: Starred plans updated:', {
count: updateResult.planIdsCount,
updatedAt: new Date(updateResult.updatedAt).toISOString()
})
} catch (error) {
console.error('❌ App.vue: Failed to configure native fetcher:', error)
console.error('❌ App.vue: Error details:', error instanceof Error ? error.stack : String(error))
logger.error('Failed to configure native fetcher:', error)
this.errorMessage = `Failed to configure native fetcher: ${error instanceof Error ? error.message : String(error)}`
}
} else {
console.log('⏭️ App.vue: Web platform - skipping configuration')
logger.info('Web platform detected - native fetcher configuration skipped')
}
// NOTE: Native fetcher configuration has been moved to HomeView.vue onMounted()
// App.vue mounted() hook is not executing reliably (likely due to Vue router lifecycle).
// HomeView.vue mounts after navigation, ensuring Capacitor is ready.
// See: src/views/HomeView.vue - configureNativeFetcher() function
console.log('🚀 App.vue: mounted() hook EXECUTED (configuration moved to HomeView)')
}
clearError() {

104
test-apps/daily-notification-test/src/views/HomeView.vue

@ -115,7 +115,10 @@ import { useRouter } from 'vue-router'
import { useAppStore } from '@/stores/app'
import ActionCard from '@/components/cards/ActionCard.vue'
import StatusCard from '@/components/cards/StatusCard.vue'
// Note: Native fetcher configuration moved to App.vue mounted() hook
import { Capacitor } from '@capacitor/core'
import { DailyNotification } from '@timesafari/daily-notification-plugin'
import { TEST_USER_ZERO_CONFIG, generateEndorserJWT } from '@/config/test-user-zero'
import { logger } from '@/lib/logger'
const router = useRouter()
const appStore = useAppStore()
@ -123,6 +126,7 @@ const appStore = useAppStore()
const isScheduling = ref(false)
const isCheckingStatus = ref(false)
const isRequestingPermissions = ref(false)
const nativeFetcherConfigured = ref(false)
const platformName = computed(() => {
const platform = appStore.platform
@ -430,10 +434,102 @@ const openConsole = (): void => {
alert('📖 Console Logs\n\nOpen your browser\'s Developer Tools (F12) and check the Console tab for detailed diagnostic information.')
}
// Initialize system status when component mounts
// Note: Native fetcher configuration is handled in App.vue mounted() hook
// Configure native fetcher for background workers
const configureNativeFetcher = async (): Promise<void> => {
// Only configure once
if (nativeFetcherConfigured.value) {
console.log('⏭️ HomeView: Native fetcher already configured, skipping')
return
}
// Only configure on native platforms
if (!Capacitor.isNativePlatform()) {
console.log('⏭️ HomeView: Web platform - skipping native fetcher configuration')
return
}
try {
console.log('🚀 HomeView: Starting native fetcher configuration...')
logger.info('Configuring native fetcher from HomeView...')
// Get API server URL
const apiBaseUrl = TEST_USER_ZERO_CONFIG.getApiServerUrl()
console.log('🔧 HomeView: API Base URL:', apiBaseUrl)
console.log('🔧 HomeView: Server Mode:', TEST_USER_ZERO_CONFIG.api.serverMode)
// Skip configuration if in mock mode
if (TEST_USER_ZERO_CONFIG.api.serverMode === 'mock') {
console.log('⏭️ HomeView: Mock mode - skipping configuration')
logger.warn('Mock mode enabled - native fetcher will not be configured')
nativeFetcherConfigured.value = true // Mark as "configured" to prevent retries
return
}
console.log('🔧 HomeView: Generating ES256K JWT token...')
// Generate JWT token for authentication
const jwtToken = await generateEndorserJWT()
console.log('✅ HomeView: JWT token generated, length:', jwtToken.length)
console.log('🔧 HomeView: Calling configureNativeFetcher with:', {
apiBaseUrl,
activeDid: TEST_USER_ZERO_CONFIG.identity.did.substring(0, 30) + '...',
jwtTokenLength: jwtToken.length
})
// Configure native fetcher with credentials
await DailyNotification.configureNativeFetcher({
apiBaseUrl: apiBaseUrl,
activeDid: TEST_USER_ZERO_CONFIG.identity.did,
jwtToken: jwtToken
})
console.log('✅ HomeView: Native fetcher configured successfully!')
logger.info('Native fetcher configured successfully', {
apiBaseUrl: apiBaseUrl.substring(0, 50) + '...',
activeDid: TEST_USER_ZERO_CONFIG.identity.did.substring(0, 30) + '...'
})
// Update starred plan IDs from config (non-blocking - if this fails, fetcher is still configured)
try {
console.log('🔧 HomeView: Updating starred plan IDs...')
const planIds = [...TEST_USER_ZERO_CONFIG.starredProjects.planIds]
console.log('🔧 HomeView: Plan IDs to update:', planIds.length, 'plans')
console.log('🔧 HomeView: Plan IDs array:', JSON.stringify(planIds))
const updateResult = await DailyNotification.updateStarredPlans({
planIds: planIds
})
console.log('✅ HomeView: Starred plans updated:', {
count: updateResult.planIdsCount,
updatedAt: new Date(updateResult.updatedAt).toISOString()
})
} catch (starredPlansError) {
// Non-critical error - native fetcher is already configured
console.warn('⚠️ HomeView: Failed to update starred plans (non-critical):', starredPlansError)
logger.warn('Starred plans update failed (native fetcher is still configured)', {
error: starredPlansError instanceof Error ? starredPlansError.message : String(starredPlansError)
})
}
// Mark as configured to prevent duplicate configuration
nativeFetcherConfigured.value = true
} catch (error) {
console.error('❌ HomeView: Failed to configure native fetcher:', error)
console.error('❌ HomeView: Error details:', error instanceof Error ? error.stack : String(error))
logger.error('Failed to configure native fetcher from HomeView:', error)
// Don't mark as configured on error, so it can retry on next mount
}
}
// Initialize system status and native fetcher when component mounts
onMounted(async () => {
console.log('🏠 HomeView mounted - checking initial system status...')
console.log('🏠 HomeView mounted - checking initial system status and configuring native fetcher...')
// Configure native fetcher first (needed for background workers)
await configureNativeFetcher()
// Then check system status
await checkSystemStatus()
})
</script>

Loading…
Cancel
Save