From cb748f91052799b381a2d70fbf0bbd086d9c293b Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Tue, 30 Jun 2026 20:36:09 +0800 Subject: [PATCH] feat(ios): mark shares processed after successful import Call SharedImage.markProcessed(shareId) from the share import workflow once a shared image has been successfully stored in the temp DB. The call is gated to iOS and a non-empty shareId, and a mark-processed failure is logged as a warning without failing the already-successful import. Add explicit logging for processing started/succeeded/failed and markProcessed invoked. On a storage failure the share is left intact and not marked processed, so it remains available for retry. Android is unchanged. --- src/main.capacitor.ts | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main.capacitor.ts b/src/main.capacitor.ts index ced3b795..37972586 100644 --- a/src/main.capacitor.ts +++ b/src/main.capacitor.ts @@ -169,12 +169,45 @@ async function checkAndStoreNativeSharedImage(): Promise<{ // Check if we have valid image data (base64 must be non-null and non-empty) if (result && result.base64 && result.base64.trim().length > 0) { const fileName = result.fileName || "shared-image.jpg"; + const shareId = result.shareId; + const shareIdLog = shareId || "unknown"; - // Store in temp database using extracted method + // Hand off to the app: store in temp database using extracted method logger.info( - "[Main] Native shared image found (via plugin), storing in temp DB", + `[Main] Shared image processing started shareId=${shareIdLog} fileName=${fileName}`, ); - await storeSharedImageInTempDB(result.base64, fileName); + + try { + await storeSharedImageInTempDB(result.base64, fileName); + } catch (storeError) { + // Processing failed - leave the shared item intact (do NOT mark processed) + logger.error( + `[Main] Shared image processing failed shareId=${shareIdLog}:`, + storeError, + ); + isProcessingSharedImage = false; + return { success: false }; + } + + logger.info( + `[Main] Shared image processing succeeded shareId=${shareIdLog} fileName=${fileName}`, + ); + + // Signal explicit completion only after successful processing. + // iOS-only: the markProcessed API is not implemented on Android. + if (shareId && Capacitor.getPlatform() === "ios") { + try { + logger.info(`[Main] markProcessed invoked shareId=${shareId}`); + await SharedImage.markProcessed({ shareId }); + } catch (markError) { + // A failure to mark processed must not fail the (already successful) + // share processing; the share simply remains available for retry. + logger.warn( + `[Main] markProcessed failed shareId=${shareId}:`, + markError, + ); + } + } isProcessingSharedImage = false; return { success: true, fileName };