Compare commits

...

32 Commits

Author SHA1 Message Date
Jose Olarte III
02e6e3427d refactor(ios): remove SharedImage plugin-readiness polling (Phase 2B-3)
The SharedImage plugin is now registered deterministically from
AppBridgeViewController.capacitorDidLoad() before the web layer loads, so
JS no longer needs to wait for it. Remove the readiness machinery that
existed solely to tolerate the old async AppDelegate registration:
waitForSharedImagePluginReady(), the sleep() helper, the
STARTUP_PLUGIN_MAX_ATTEMPTS/RETRY_DELAY_MS constants and retry loop, and
the three readiness-only console diagnostics (waiting / ready after N /
giving up).

The iOS startup branch now calls checkForSharedImageAndNavigate()
immediately. All other share-target behavior is unchanged: cold-start,
extension, and launch diagnostics; native trace APIs; the Share Target
Debug Panel; appStateChange/appUrlOpen handling; actual shared-image
handling; and the Android startup path. No JS readiness diagnostics
remain; no Android changes.
2026-06-26 21:14:59 +08:00
Jose Olarte III
337a8f7536 refactor(ios): remove AppDelegate SharedImage registration (Phase 2B-2)
Now that AppBridgeViewController registers SharedImagePlugin from
capacitorDidLoad(), remove the obsolete plugin-registration logic from
AppDelegate: the 5-attempt retry loop in didFinishLaunchingWithOptions,
the registerSharedImagePlugin() method, and the registration-specific
logging. SharedImagePlugin is now registered from a single, deterministic
site.

All non-registration responsibilities are unchanged: notification
handling, URL and universal-link proxying, SharedPhotoReady activation
logic, every lifecycle callback, the temporary app launch tracing, and
all temporary share-target diagnostics remain intact. No JS or Android
changes.
2026-06-26 19:35:43 +08:00
Jose Olarte III
4978e93711 feat(ios): register SharedImage via CAPBridgeViewController subclass (Phase 2B-1)
Introduce AppBridgeViewController, a CAPBridgeViewController subclass that
registers the app-local SharedImagePlugin from capacitorDidLoad(), where
the Capacitor bridge is guaranteed to exist. This is the first step toward
replacing AppDelegate's timed retry registration with a deterministic,
bridge-ready registration point.

Point the existing root bridge controller in Main.storyboard at
AppBridgeViewController (same VC id/scene; only the custom class changes)
and add the new file to the App target in project.pbxproj.

The existing AppDelegate registration and its retry loop are intentionally
left in place as a temporary safety net, so the plugin is now registered
from both sites during this phase. No diagnostics, retry logic, JS, or
Android code changed; plugin name ("SharedImage") and implementation are
unchanged.
2026-06-26 19:26:00 +08:00
Jose Olarte III
9941264022 chore(ios): add temporary Share Target debug panel (temporary)
Add a dedicated, temporary debug view for the iOS Share Target
investigation so native traces can be inspected without attaching Xcode.
Kept separate from the Notification/Notiwind test panel so it is easy to
remove once the investigation is complete.

The panel (src/views/ShareTargetDebugView.vue, route
/share-target-debug) has three buttons:
- Dump Native Traces: calls SharedImage.getShareExtensionTrace() and
  getAppLaunchTrace(), logs both in full (untruncated) between
  EXTENSION TRACE START/END and APP LAUNCH TRACE START/END markers, and
  shows them in read-only scrollable fields.
- Clear Share Extension Trace: clears the native log and the field.
- Clear App Launch Trace: clears the native log and the field.

Register the route alongside the existing /test debug route and link to
the panel from TestView. No share-target behavior changed; Android
untouched. All additions marked TEMPORARY SHARE TARGET DIAGNOSTICS.
2026-06-26 18:10:08 +08:00
Jose Olarte III
256018d30d chore(ios): add native app launch lifecycle trace diagnostics (temporary)
Add temporary, append-only tracing of the native iOS application launch
lifecycle to diagnose failed cold-start shares when Xcode is not
attached during launch. Writes app-launch-trace.log in the same App
Group container as share-extension-trace.log, reusing the same style
(ISO8601 timestamps, append-only, all logging failures swallowed).

AppDelegate now traces every lifecycle callback
(didFinishLaunchingWithOptions, application(open:),
applicationDidBecomeActive, applicationWill/DidEnterForeground/Background,
applicationWillResignActive, applicationWillTerminate, and
checkForSharedImageOnActivation), recording the callback name, whether a
URL was supplied, the URL value, whether it matches timesafari://,
whether launch options carried a URL, and whether shared-image
activation ran.

Expose read-only getAppLaunchTrace()/clearAppLaunchTrace() plugin APIs
(mirroring the share-extension trace APIs) with matching TypeScript
definitions and web stubs. main.capacitor.ts logs the full launch trace
between APP LAUNCH TRACE START/END markers inside the existing
diagnostics block.

No share-target behavior changed; Android untouched. All additions are
marked TEMPORARY SHARE TARGET DIAGNOSTICS.
2026-06-26 17:06:50 +08:00
Jose Olarte III
c1a5bae5c8 feat(ios): wait for SharedImage plugin before initial startup check (Phase 2A)
Eliminate the iOS startup race between asynchronous SharedImage plugin
registration and the first shared-image check. Previously the initial
check fired on a fixed 1000ms timer that only assumed the native plugin
(registered by AppDelegate with retries from T+500ms) was ready, so a
slow registration could make the first getSharedImage() call throw and
miss a cold-start share.

Replace the fixed delay with waitForSharedImagePluginReady(), which
probes the plugin via a read-only hasSharedImage() call and retries
within a bounded budget (10 attempts, 300ms apart) until the plugin
actually responds. The initial check runs only once readiness is
confirmed, with a best-effort fallback if the budget is exhausted.

Scope is limited to the initial startup check on iOS. appStateChange,
appUrlOpen/handleDeepLink, router navigation, share processing, Android
behavior, and all native Swift code are unchanged. Temporary
share-target diagnostics are preserved and extended with startup
readiness logging.

Document the change as a Phase 2A section in
doc/share-target-ios-audit.md.
2026-06-26 16:48:00 +08:00
Jose Olarte III
c9061e669e docs(ios): add share-target launch and deep-link flow audit
Add doc/share-target-ios-launch-flow-audit.md documenting the iOS
Share Extension launch path from openMainApp("timesafari://") through
the native AppDelegate, Capacitor bridge, and JS bootstrap to
/shared-photo navigation.

Covers cold- vs warm-start execution order, the single appUrlOpen
listener and its call graph, all shared-image detection mechanisms
(startup timer, appStateChange, applicationDidBecomeActive,
sharedPhotoReady flag, SharedPhotoReady notification), native launch-URL
handling, and a timing analysis of the race conditions.

Key findings: cold-start shares rely on the T+1000ms startup timer
reading the App Group payload (not appUrlOpen, which registers at
T+2000ms after the launch URL is delivered); warm-start shares are
driven by appUrlOpen/appStateChange; the launch URL event and the
SharedPhotoReady notification can be lost before JS is ready, but the
durable App Group payload is not. Audit only; no code changes.
2026-06-26 15:43:42 +08:00
Jose Olarte III
7b1fec779b chore(ios): log full Share Extension trace on startup (temporary)
Surface the complete Share Extension execution trace during app startup
so the cold-start share path can be inspected even when Xcode truncates
console output.

In checkForSharedImageAndNavigate(), after the existing diagnostics
call, retrieve SharedImage.getShareExtensionTrace() and:
- log the full untruncated trace between TRACE FULL START/END markers
- show the full trace in a user-visible alert (iOS only)
- log TRACE LENGTH and the first 500 characters

Share-target behavior is unchanged and the trace work is gated to iOS,
so Android is unaffected. All additions are marked with
"TEMPORARY SHARE TARGET DIAGNOSTICS".
2026-06-25 19:57:42 +08:00
Jose Olarte III
d1106d9aec chore(ios): add Share Extension execution trace diagnostics (temporary)
Add a lightweight, temporary trace logger to diagnose where the iOS
Share Extension stops executing during a failed cold-start share.

- ShareViewController: add appendTrace() helper that writes ISO8601-
  prefixed lines to share-extension-trace.log in the App Group
  container, ignoring failures (diagnostics only)
- Add trace entries across the share flow: viewDidLoad,
  processAndOpenApp, processSharedImage, image attachment/load,
  storeImageData, setSharedPhotoReadyFlag, openMainApp, completeRequest
- SharedImageUtility: add getShareExtensionTrace() (read-only) and
  clearShareExtensionTrace() (deletes the trace file)
- SharedImagePlugin: expose getShareExtensionTrace() and
  clearShareExtensionTrace() to JS
- definitions.ts / SharedImagePlugin.web.ts: add ShareExtensionTrace
  type, method signatures, and web stubs

Share behavior is unchanged and Android is untouched. All additions are
marked with "TEMPORARY SHARE TARGET DIAGNOSTICS".
2026-06-25 19:10:57 +08:00
Jose Olarte III
6f7be2e3b2 chore(ios): add pendingShareExists cold-start share diagnostics (temporary)
Extend ShareExtensionDiagnostics with pendingShareExists across
SharedImageUtility, definitions, and the web stub, and log cold-start
state (pending share + current route) in the iOS startup share check.
2026-06-25 18:37:04 +08:00
Jose Olarte III
4fc30562fb docs(ios): add App Group configuration audit for share extension
Document App/extension entitlements, bundle IDs, teams, and signing,
flagging a code-vs-entitlement App Group ID mismatch (code uses
group.app.timesafari.share while entitlements grant
group.app.trentlarson.timesafari.share) that breaks shared storage.
2026-06-25 17:48:53 +08:00
Jose Olarte III
6afe40bc23 docs(ios): add Share Extension configuration audit
Document that TimeSafariShareExtension is a code-based extension with
ShareViewController as NSExtensionPrincipalClass, confirm viewDidLoad
executes on launch, and note no blocking Info.plist/storyboard mismatches.
2026-06-25 17:28:20 +08:00
Jose Olarte III
402bd2681f chore(ios): log share extension diagnostics on startup (temporary)
Call getShareExtensionDiagnostics() during the iOS shared-image startup
check and print the result to Xcode logs for share-target investigation.
2026-06-24 19:43:27 +08:00
Jose Olarte III
498a4926bf feat(ios): add Share Extension startup diagnostic marker and API
Write shareExtensionLastStart on ShareViewController.viewDidLoad and
expose getShareExtensionDiagnostics() through SharedImagePlugin with
shareId, file path, and fileExists for debugging failed share flows.
2026-06-24 19:38:25 +08:00
Jose Olarte III
f0ca49b5dc feat(ios): add diagnostic logging to Share Extension share flow
Log start/end, shareId, attachment counts, UTType, byte counts, filenames,
and every early return across viewDidLoad through completeRequest to trace
how far a share progresses when debugging failures.
2026-06-24 19:28:09 +08:00
Jose Olarte III
07463246f0 feat(ios): add share-target diagnostic logging in SharedImageUtility
Log shareId, sharedPhotoFilePath, metadataExists, and fileExists at the
start of getSharedImageData() and hasSharedImage() to debug pending
App Group shares without changing retrieval behavior.
2026-06-24 17:19:54 +08:00
Jose Olarte III
79ceebbd1d feat(ios): make shared image retrieval non-destructive (Phase 1C)
Stop deleting App Group metadata and image files in getSharedImageData()
so retrieval is read-only while preserving the existing plugin API shape.
Document removed deletion paths in the iOS share target audit.
2026-06-24 16:49:45 +08:00
Jose Olarte III
ddbd07f315 feat(ios): use UUID-based filenames for shared images (Phase 1B)
Store shared images as <shareId>.<ext> in the App Group container while
keeping the original filename in metadata, preventing on-disk collisions
without changing retrieval, deletion, or JS consumer behavior.
2026-06-23 19:37:11 +08:00
Jose Olarte III
35a6a6bfb3 feat(ios): add share ID tracking for share target (Phase 1A)
Generate a UUID per incoming share in the Share Extension, persist it
as sharedPhotoShareId in App Group metadata, and add [ShareTarget] logs
for receive/store/retrieve events without changing retrieval or deletion.
2026-06-23 19:13:44 +08:00
Jose Olarte III
08a55202f5 docs(ios): add share target implementation audit
Document the Share Extension → App Group → main app flow, including
read/write/delete points, startup detection hooks, timing behavior,
and race conditions to support share-target reliability work.
2026-06-23 17:20:53 +08:00
ec41dd52d5 bump version to v 1.4.3 build 69 2026-06-21 10:59:24 -06:00
463db39a6b remove hard-coded daily android notification 2026-06-19 23:43:40 -06:00
fe97dff752 Merge pull request 'Rework Thanks Button' (#234) from thanks-button-rework into master
Reviewed-on: #234
2026-06-19 07:21:37 +00:00
Jose Olarte III
903047f13b style(gift): center entity selection step heading and entity type toggle 2026-06-18 21:09:32 +08:00
Jose Olarte III
48be234af4 fix(home): offset scrolled Thank button for safe-area-inset-bottom 2026-06-17 17:57:13 +08:00
6c0907d905 remove unused function & duplicate comment 2026-06-16 16:09:31 -06:00
Jose Olarte III
8d8bcf2a7e style(home): rework Thank button and sticky scroll action bar
Replace the floating circular plus FAB with a full-width bottom bar that
matches the inline Thank button. Wrap the quick-action section in a styled
container and raise the scroll threshold to 120px.
2026-06-16 21:48:34 +08:00
a4b47904c8 Merge pull request 'Add footer to Gifted Details view' (#233) from gifted-details-footer into master
Reviewed-on: #233
2026-06-16 08:27:47 +00:00
Jose Olarte III
bb890baacf fix(gifted-details): add QuickNav footer navigation 2026-06-15 17:20:18 +08:00
dae23300fe point to a single .entitlements file (undo most of previous commit) 2026-06-02 15:50:17 -06:00
9e401febea add 'share' to the entitlements for production, for sharing with this app 2026-06-02 15:46:36 -06:00
cd4b279703 Merge pull request '16kb-pages' (#232) from 16kb-pages into master
Reviewed-on: #232
2026-05-25 20:01:18 +00:00
30 changed files with 3231 additions and 1099 deletions

View File

@@ -1140,7 +1140,7 @@ export GEM_PATH=$shortened_path
##### 1. Bump the version in package.json & CHANGELOG.md for `MARKETING_VERSION`, then `grep CURRENT_PROJECT_VERSION ios/App/App.xcodeproj/project.pbxproj` and add 1 for the numbered version here:
```bash
cd ios/App && xcrun agvtool new-version 68 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.4.2;/g" App.xcodeproj/project.pbxproj && cd -
cd ios/App && xcrun agvtool new-version 69 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.4.3;/g" App.xcodeproj/project.pbxproj && cd -
# Unfortunately this edits Info.plist directly.
#xcrun agvtool new-marketing-version 0.4.5
```
@@ -1419,8 +1419,8 @@ The recommended way to build for Android is using the automated build script:
##### 1. Bump the version in package.json, then update these versions & run:
```bash
perl -p -i -e 's/versionCode .*/versionCode 68/g' android/app/build.gradle
perl -p -i -e 's/versionName .*/versionName "1.4.2"/g' android/app/build.gradle
perl -p -i -e 's/versionCode .*/versionCode 69/g' android/app/build.gradle
perl -p -i -e 's/versionName .*/versionName "1.4.3"/g' android/app/build.gradle
```
##### 2. Build

View File

@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.3] - 2026.06.19
### Removed
- Automatic "Check your starred projects" daily notification
### Changed
- Positioning for 'Thank' button and entity-type toggle link
## [1.4.2] - 2026.05.24
### Changed
- Support 16 KB page sizes

View File

@@ -37,8 +37,8 @@ android {
applicationId "app.timesafari.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 68
versionName "1.4.2"
versionCode 69
versionName "1.4.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

View File

@@ -9,7 +9,6 @@ import org.timesafari.dailynotification.FetchContext;
import org.timesafari.dailynotification.NativeNotificationContentFetcher;
import org.timesafari.dailynotification.NotificationContent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -47,22 +46,11 @@ public class TimeSafariNativeFetcher implements NativeNotificationContentFetcher
// This should query the TimeSafari API for notification content
// using the configured apiBaseUrl, activeDid, and jwtToken
// For now, return a placeholder notification
long scheduledTime = fetchContext.scheduledTime != null
? fetchContext.scheduledTime
: System.currentTimeMillis() + 60000; // 1 minute from now
NotificationContent content = new NotificationContent(
"TimeSafari Update",
"Check your starred projects for updates!",
scheduledTime
);
List<NotificationContent> results = new ArrayList<>();
results.add(content);
Log.d(TAG, "Returning " + results.size() + " notification(s)");
return results;
// Not implemented yet: return no content rather than fabricating a
// placeholder notification (previously hardcoded "Check your starred
// projects for updates!", which showed on every app startup).
Log.d(TAG, "Content fetching not yet implemented; returning no notifications");
return Collections.<NotificationContent>emptyList();
} catch (Exception e) {
Log.e(TAG, "Fetch failed", e);

View File

@@ -0,0 +1,155 @@
# iOS App Group Configuration Audit
**Generated:** 2026-06-25 17:31:15 PST
## Scope
Static inspection of App Group configuration for the **App** target and the **TimeSafariShareExtension** target: entitlements, capabilities, bundle identifiers, Debug/Release build settings, and signing. No code was modified.
### Files Inspected
| File | Role |
|------|------|
| `ios/App/App/App.entitlements` | App target App Group declaration |
| `ios/App/TimeSafariShareExtension/TimeSafariShareExtension.entitlements` | Extension App Group declaration |
| `ios/App/App.xcodeproj/project.pbxproj` | Bundle IDs, teams, signing, entitlement linkage |
| `ios/App/App/SharedImageUtility.swift` | App Group identifier used by main app code |
| `ios/App/TimeSafariShareExtension/ShareViewController.swift` | App Group identifier used by extension code |
---
## CRITICAL FINDING — Code vs Entitlements App Group Mismatch
The entitlements and the Swift source declare **different** App Group identifiers:
| Location | App Group identifier |
|----------|----------------------|
| `App.entitlements` | `group.app.trentlarson.timesafari.share` |
| `TimeSafariShareExtension.entitlements` | `group.app.trentlarson.timesafari.share` |
| `SharedImageUtility.swift` (`appGroupIdentifier`) | `group.app.timesafari.share` |
| `ShareViewController.swift` (`appGroupIdentifier`) | `group.app.timesafari.share` |
The runtime code targets `group.app.timesafari.share`, but **neither target is entitled to that group** — both entitlements now grant `group.app.trentlarson.timesafari.share`.
This is an **uncommitted change**: `git diff` shows both entitlements were just changed from `group.app.timesafari.share``group.app.trentlarson.timesafari.share`, while the Swift code still uses the old value. Before this edit the code and entitlements matched; after it they do not.
### Runtime Consequences
- `FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.app.timesafari.share")` returns **nil** (the app is not entitled to that group). The extension's `storeImageData` aborts via `guard let containerURL` → image file is never written; the main app's reads return nil.
- `UserDefaults(suiteName: "group.app.timesafari.share")` does **not** resolve to the shared, entitled suite. Writes fall back to each process's own preferences domain, so the extension's keys (`sharedPhotoFilePath`, `sharedPhotoShareId`, `shareExtensionLastStart`, `sharedPhotoReady`) are **not visible** to the main app.
Net effect: the entire share-target handoff via the App Group breaks while this mismatch exists. This is the most likely root cause of "App Group UserDefaults writes failing."
**Note:** This affects both Debug and Release (the entitlements have no per-configuration variants), not Debug only.
---
## Direct Answers
### Do both targets declare the same App Group?
**Yes — the two entitlements files match each other.** Both `App.entitlements` and `TimeSafariShareExtension.entitlements` declare exactly:
```xml
<key>com.apple.security.application-groups</key>
<array>
<string>group.app.trentlarson.timesafari.share</string>
</array>
```
However, **the code does not match the entitlements** (see Critical Finding). So "same App Group" is true at the entitlement level, false at the entitlement-vs-code level.
### Are there any Debug vs Release differences?
**Entitlements / App Group:** No. A single entitlements file per target applies to both configurations; the App Group string is identical in Debug and Release (`group.app.trentlarson.timesafari.share`).
**Bundle identifiers:** Yes — they differ by configuration:
| Target | Debug | Release |
|--------|-------|---------|
| App | `app.trentlarson.timesafari` | `app.timesafari` |
| Extension | `app.trentlarson.timesafari.TimeSafariShareExtension` | `app.timesafari.TimeSafariShareExtension` |
(The Debug bundle IDs were just changed from the `app.timesafari*` form per `git diff`.)
**Development team:** Yes — differs by configuration (see next answer).
In both configurations the extension bundle ID is correctly nested under the app bundle ID, which is required for an app extension.
### Are there any team-ID differences that could affect App Group access?
| Configuration | App team | Extension team | Match? |
|---------------|----------|----------------|--------|
| Debug | `7XVXYPEQYJ` | `7XVXYPEQYJ` | ✅ same |
| Release | `GM3FS5JQPH` | `GM3FS5JQPH` | ✅ same |
- **Within each configuration, both targets use the same team** — this is the condition required for two targets to share an App Group, and it is satisfied.
- **Across configurations the teams differ** (Debug `7XVXYPEQYJ` vs Release `GM3FS5JQPH`). The Debug team was just changed from `GM3FS5JQPH` per `git diff`.
Implications:
1. The App Group container is namespaced by Team ID at runtime (`$(TeamID).group...`). A Debug install (team `7XVXYPEQYJ`) and a Release install (team `GM3FS5JQPH`) use **different physical containers** and cannot share data with each other. This is normal and only matters if you expect data continuity between Debug and Release builds.
2. With **Automatic** signing, the App Group `group.app.trentlarson.timesafari.share` must be registered/enabled for **both** teams. If it is not provisioned under the Debug team `7XVXYPEQYJ`, automatic signing of the Debug build can fail to include the App Group entitlement (or fail to sign), which would also break App Group access in Debug.
### Are there signing/entitlement mismatches that could cause App Group UserDefaults writes to fail in Debug builds?
**Yes.** In order of severity:
1. **(Primary) Code/entitlement group-ID mismatch.** Code uses `group.app.timesafari.share`; entitlements grant `group.app.trentlarson.timesafari.share`. The code's group is not entitled, so shared `UserDefaults`/container access fails. Affects Debug and Release.
2. **(Debug-specific risk) App Group provisioning under the Debug team.** Debug now signs with team `7XVXYPEQYJ` (changed from `GM3FS5JQPH`). Under Automatic signing, if `group.app.trentlarson.timesafari.share` is not enabled for team `7XVXYPEQYJ`, the Debug build's App Group entitlement may not be granted, causing writes to silently fall back to the local domain.
3. **(Consistency) Bundle-ID change accompanying the team change.** Debug bundle IDs changed to `app.trentlarson.timesafari*`. App Groups don't have to match bundle IDs, so this is not a direct cause, but combined with the new team it means Debug provisioning is a distinct profile/identifier set that must independently carry the App Group capability.
No mismatch was found **between the two entitlement files themselves**, and no per-configuration entitlement override exists.
---
## Detailed Configuration
### Entitlements (identical content in both files)
```xml
<key>com.apple.security.application-groups</key>
<array>
<string>group.app.trentlarson.timesafari.share</string>
</array>
```
`CODE_SIGN_ENTITLEMENTS` linkage (both Debug and Release):
| Target | Entitlements path |
|--------|-------------------|
| App | `App/App.entitlements` |
| Extension | `TimeSafariShareExtension/TimeSafariShareExtension.entitlements` |
### Bundle Identifiers, Teams, Signing (project.pbxproj)
| Setting | App Debug | App Release | Ext Debug | Ext Release |
|---------|-----------|-------------|-----------|-------------|
| `PRODUCT_BUNDLE_IDENTIFIER` | `app.trentlarson.timesafari` | `app.timesafari` | `app.trentlarson.timesafari.TimeSafariShareExtension` | `app.timesafari.TimeSafariShareExtension` |
| `DEVELOPMENT_TEAM` | `7XVXYPEQYJ` | `GM3FS5JQPH` | `7XVXYPEQYJ` | `GM3FS5JQPH` |
| `CODE_SIGN_STYLE` | Automatic | Automatic | Automatic | Automatic |
| `CODE_SIGN_ENTITLEMENTS` | `App/App.entitlements` | same | `TimeSafariShareExtension/...entitlements` | same |
| App Group (from entitlements) | `group.app.trentlarson.timesafari.share` | same | same | same |
### App Group Identifier Used in Code
```swift
// SharedImageUtility.swift:13 and ShareViewController.swift:13
private let appGroupIdentifier = "group.app.timesafari.share" // does NOT match entitlements
```
---
## Recommendations (no code changed)
1. **Resolve the group-ID mismatch.** Either revert the entitlements back to `group.app.timesafari.share`, or update the two Swift constants to `group.app.trentlarson.timesafari.share`. Both sides must use one identical string.
2. **Confirm App Group provisioning per team.** Ensure `group.app.trentlarson.timesafari.share` (whichever string is chosen) is enabled for both `7XVXYPEQYJ` (Debug) and `GM3FS5JQPH` (Release) so Automatic signing includes the capability in both configurations.
3. **Decide whether the Debug↔Release team/bundle-ID split is intentional.** If cross-config data continuity is ever expected, note that different Team IDs yield different App Group containers.
4. **Verify at runtime** using the existing `getShareExtensionDiagnostics()` / `[ShareTarget]` logs: after aligning identifiers, `shareExtensionLastStart` written by the extension should become readable by the main app.
---
## Conclusion
The two **entitlement files agree** on the App Group (`group.app.trentlarson.timesafari.share`) and, **within each build configuration**, both targets share the same Development Team and consistent nested bundle IDs — the structural requirements for App Group sharing are met. The decisive problem is that the **Swift code still references the old group `group.app.timesafari.share`**, which no entitlement grants; this breaks both shared `UserDefaults` and the shared container in all builds. Secondarily, the recent Debug switch to team `7XVXYPEQYJ` means the chosen App Group must be provisioned under that team for Debug App Group access to work under Automatic signing.

View File

@@ -0,0 +1,188 @@
# iOS Share Extension Configuration Audit
**Generated:** 2026-06-25 15:33:39 PST
## Scope
Static inspection of the `TimeSafariShareExtension` target configuration to determine the extension entry point, principal view controller, storyboard vs. code-based setup, and whether `ShareViewController.viewDidLoad()` is guaranteed to execute. No code was modified.
### Files Inspected
| File | Role |
|------|------|
| `ios/App/App.xcodeproj/project.pbxproj` | Target, build settings, file membership |
| `ios/App/TimeSafariShareExtension/Info.plist` | NSExtension configuration |
| `ios/App/TimeSafariShareExtension/ShareViewController.swift` | Principal class implementation |
| `ios/App/TimeSafariShareExtension/TimeSafariShareExtension.entitlements` | App Group access |
---
## Direct Answers
### 1. What class is configured as the extension entry point?
`ShareViewController`, resolved via `Info.plist` key `NSExtensionPrincipalClass`:
```xml
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
```
`$(PRODUCT_MODULE_NAME)` resolves to `TimeSafariShareExtension` (derived from `PRODUCT_NAME = $(TARGET_NAME)`), so the runtime entry point is `TimeSafariShareExtension.ShareViewController`.
### 2. Is ShareViewController actually the configured principal view controller?
**Yes.** `ShareViewController.swift` declares:
```swift
class ShareViewController: UIViewController {
```
within the `TimeSafariShareExtension` target. The class name, module, and `UIViewController` base class match the `NSExtensionPrincipalClass` reference. There is no competing storyboard-designated initial controller, so `ShareViewController` is unambiguously the principal view controller.
### 3. Is the extension storyboard-based or code-based?
**Code-based.**
- `Info.plist` contains `NSExtensionPrincipalClass` and does **not** contain `NSExtensionMainStoryboard`.
- The extension folder contains no `.storyboard` file (only `Info.plist`, `ShareViewController.swift`, and the entitlements file).
- The only storyboards in the project (`Main.storyboard`, `LaunchScreen.storyboard`) belong exclusively to the **App** target's resources, not the extension.
This deviates from the default Xcode Share Extension template (which ships a `MainInterface.storyboard` + `NSExtensionMainStoryboard`). The deviation is intentional and internally consistent.
### 4. Does the configuration guarantee that ShareViewController.viewDidLoad() executes when the extension launches?
**Yes, under normal launch.** Because:
- The principal class is a `UIViewController` subclass, the extension host instantiates it and installs its view into the extension's window. This triggers the standard view lifecycle: `loadView()``viewDidLoad()`.
- `ShareViewController` overrides `viewDidLoad()` and calls `super.viewDidLoad()`, then immediately runs `processAndOpenApp()`. The startup marker (`shareExtensionLastStart`) and `[ShareTarget] viewDidLoad started` log execute before any other logic.
- The Swift source is compiled into the extension target via the Xcode 16 **file-system synchronized group** (`PBXFileSystemSynchronizedRootGroup` for `TimeSafariShareExtension`), so the class is guaranteed to be present in the built `.appex`.
**Caveats (not failures, but worth noting):**
- The guarantee holds only if the OS successfully resolves and instantiates the principal class. If `$(PRODUCT_MODULE_NAME)` ever diverges from the actual Swift module name (e.g., a custom `PRODUCT_MODULE_NAME`), runtime class lookup would fail and the extension would not launch. Currently they match.
- `viewDidLoad()` executing does not, by itself, guarantee the *share* succeeds — the asynchronous `loadItem` work in `processSharedImage` happens after `viewDidLoad` returns.
### 5. Are there any mismatches between Info.plist, storyboard, and ShareViewController?
**No blocking mismatches.** Details:
| Check | Result |
|-------|--------|
| `NSExtensionPrincipalClass` ↔ Swift class name | Match (`ShareViewController`) |
| Principal class module ↔ target module | Match (`TimeSafariShareExtension`) |
| `NSExtensionMainStoryboard` ↔ storyboard file | Consistent — neither exists (code-based) |
| Activation rule ↔ implementation | Consistent — `NSExtensionActivationSupportsImageWithMaxCount = 1` matches first-image-only handling |
| `NSExtensionPointIdentifier` | `com.apple.share-services` (correct for a Share extension) |
| Source file membership | `ShareViewController.swift` compiled via synchronized group |
See "Observations / Non-Blocking Notes" for environment-specific items.
---
## Detailed Configuration
### NSExtension (Info.plist)
```xml
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
</dict>
```
| Key | Value | Meaning |
|-----|-------|---------|
| `NSExtensionPointIdentifier` | `com.apple.share-services` | Registers as a Share sheet extension |
| `NSExtensionPrincipalClass` | `$(PRODUCT_MODULE_NAME).ShareViewController` | Code-based entry point |
| `NSExtensionActivationRule` | `…ImageWithMaxCount = 1` | Activates for shares containing at least one image; processes one |
| `NSExtensionMainStoryboard` | *absent* | Confirms code-based (no storyboard UI) |
### TimeSafariShareExtension Target (project.pbxproj)
| Attribute | Value |
|-----------|-------|
| `isa` | `PBXNativeTarget` |
| `productType` | `com.apple.product-type.app-extension` |
| `productReference` | `TimeSafariShareExtension.appex` |
| `CreatedOnToolsVersion` | `26.1.1` |
| File membership | `fileSystemSynchronizedGroups``TimeSafariShareExtension` (auto-membership) |
| Sources build phase | Empty explicit list (handled by synchronized group) |
| `Info.plist` membership | Excepted from synchronized group (`PBXFileSystemSynchronizedBuildFileExceptionSet`) |
| Embedded into | App target's "Embed Foundation Extensions" copy phase |
| Target dependency | App target depends on `TimeSafariShareExtension` |
### Extension Build Settings (Debug / Release)
| Setting | Debug | Release |
|---------|-------|---------|
| `INFOPLIST_FILE` | `TimeSafariShareExtension/Info.plist` | same |
| `GENERATE_INFOPLIST_FILE` | `YES` | `YES` |
| `PRODUCT_NAME` | `$(TARGET_NAME)``TimeSafariShareExtension` | same |
| `PRODUCT_BUNDLE_IDENTIFIER` | `app.trentlarson.timesafari.TimeSafariShareExtension` | `app.timesafari.TimeSafariShareExtension` |
| `CODE_SIGN_ENTITLEMENTS` | `TimeSafariShareExtension/TimeSafariShareExtension.entitlements` | same |
| `IPHONEOS_DEPLOYMENT_TARGET` | `14.0` | `14.0` |
| `DEVELOPMENT_TEAM` | `7XVXYPEQYJ` | `GM3FS5JQPH` |
| `SWIFT_VERSION` | `5.0` | `5.0` |
| `SKIP_INSTALL` | `YES` | `YES` |
`PRODUCT_MODULE_NAME` is not overridden, so it defaults to `PRODUCT_NAME` = `TimeSafariShareExtension`, making the principal class resolve to `TimeSafariShareExtension.ShareViewController`.
### ShareViewController Linkage
```swift
import UIKit
import UniformTypeIdentifiers
class ShareViewController: UIViewController {
...
override func viewDidLoad() {
// writes shareExtensionLastStart, logs, then super + processAndOpenApp()
}
}
```
- Subclass of `UIViewController` → eligible as a code-based principal class.
- Lives in the `TimeSafariShareExtension` target via the synchronized group.
- No `@objc(...)` annotation is required because the principal class is referenced with the fully-qualified Swift name (`module.Class`).
### Scene / Lifecycle Configuration
- **No** `UIApplicationSceneManifest` / `UISceneConfigurations` in the extension `Info.plist`.
- **No** `SceneDelegate` in the extension target.
- The extension relies entirely on the principal `UIViewController` lifecycle (`viewDidLoad``processAndOpenApp``processSharedImage``completeRequest`).
- The main app (`AppDelegate`) is a `UIApplicationDelegate` and is unrelated to the extension's lifecycle except via the shared App Group.
### App Group Linkage
`TimeSafariShareExtension.entitlements` grants `group.app.timesafari.share`, matching the App target's entitlement. This is what allows `viewDidLoad()`'s `shareExtensionLastStart` write to be visible to the main app's `getShareExtensionDiagnostics()`.
---
## Observations / Non-Blocking Notes
1. **Config-dependent bundle IDs & teams.** Debug uses `app.trentlarson.timesafari*` with team `7XVXYPEQYJ`; Release uses `app.timesafari*` with team `GM3FS5JQPH`. Within each configuration the extension bundle ID is correctly nested under the app bundle ID. Ensure provisioning profiles for both teams include the App Group capability.
2. **`GENERATE_INFOPLIST_FILE = YES` alongside an explicit `INFOPLIST_FILE`.** Xcode merges auto-generated keys into the supplied `Info.plist`. This is supported and the explicit `NSExtension` block is preserved; no conflict observed.
3. **Deployment target gap.** Extension targets iOS 14.0 while the App target targets iOS 15.5. Valid (an extension may target lower), and not a launch concern.
4. **Principal-class resolution dependency.** The launch guarantee depends on `$(PRODUCT_MODULE_NAME)` matching the compiled module. If `PRODUCT_MODULE_NAME` is later customized or the target renamed without updating expectations, the OS would fail to instantiate `ShareViewController` and `viewDidLoad()` would never run. Currently consistent.
5. **Code-based template divergence.** Since there is no `MainInterface.storyboard`, any future tooling or documentation that assumes the stock storyboard-based Share Extension template will not apply here.
---
## Conclusion
The `TimeSafariShareExtension` is a **code-based** Share extension whose entry point is `ShareViewController` (a `UIViewController` subclass) via `NSExtensionPrincipalClass`. The Info.plist, (absent) storyboard, and Swift implementation are mutually consistent. Under normal extension launch, `ShareViewController.viewDidLoad()` is guaranteed to run, executing the startup marker and the share-processing pipeline. No blocking misconfiguration was found; only environment-specific items (signing identities, principal-class resolution dependency) warrant ongoing attention.

View File

@@ -0,0 +1,524 @@
# iOS Share Target Implementation Audit
**Generated:** 2026-06-23 17:07:21 PST
## Overview
The iOS share target uses a **Share Extension** (`TimeSafariShareExtension`) that writes a shared image to an **App Group** container (`group.app.timesafari.share`), then opens the main app via `timesafari://`. The main app reads the image through a native **Capacitor plugin** (`SharedImagePlugin`) and stores it in the JS temp database before routing to `/shared-photo`.
### App Group Storage Model
| Key | Storage | Written by | Purpose |
|-----|---------|------------|---------|
| `sharedPhotoFilePath` | UserDefaults (suite) | Share Extension | On-disk filename in container (`<shareId>.<ext>`) |
| `sharedPhotoFileName` | UserDefaults (suite) | Share Extension | Original display filename from source app |
| `sharedPhotoShareId` | UserDefaults (suite) | Share Extension | Unique UUID per incoming share (Phase 1A) |
| `sharedPhotoReady` | UserDefaults (suite) | Share Extension | Boolean signal that a new share is available |
| `sharedPhotoBase64` | UserDefaults (suite) | *(legacy, not written)* | Removed on write for cleanup |
| Image file | App Group filesystem | Share Extension | Raw image bytes at `{container}/{sharedPhotoFilePath}` (`<shareId>.<ext>`) |
---
## End-to-End Flow
```
External App (Photos, Safari, etc.)
┌─────────────────────────────────────┐
│ TimeSafariShareExtension │
│ ShareViewController │
│ 1. viewDidLoad → processAndOpenApp │
│ 2. processSharedImage (async) │
│ 3. storeImageData → file + metadata │
│ 4. setSharedPhotoReadyFlag │
│ 5. openMainApp (timesafari://) │
│ 6. completeRequest │
└─────────────────────────────────────┘
▼ App Group: group.app.timesafari.share
│ (UserDefaults keys + image file)
┌─────────────────────────────────────┐
│ Main App (app.timesafari) │
│ │
│ Native detection: │
│ • AppDelegate.applicationDidBecome │
│ Active → checkForSharedImageOn │
│ Activation (flag only) │
│ • AppDelegate.application(open:) │
│ → Capacitor URL handling │
│ │
│ JS detection (main.capacitor.ts): │
│ • setTimeout 1000ms startup check │
│ • appStateChange (isActive) │
│ • appUrlOpen → timesafari:// │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ SharedImagePlugin.getSharedImage() │
│ → SharedImageUtility │
│ .getSharedImageData() │
│ (read-only; leaves native data intact) │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ main.capacitor.ts │
│ storeSharedImageInTempDB() │
│ → SQLite temp table │
│ → router.push/replace /shared-photo│
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ SharedPhotoView.vue │
│ loadSharedImage() │
│ → reads temp DB, deletes temp row │
│ → displays image, user action │
└─────────────────────────────────────┘
```
---
## Component Responsibilities
### Share Extension (Writer)
| File | Method | Responsibility |
|------|--------|----------------|
| `ios/App/TimeSafariShareExtension/ShareViewController.swift` | `viewDidLoad()` | Entry point; triggers share processing on load |
| | `processAndOpenApp()` | Orchestrates image extraction, flag set, app open, extension completion |
| | `processSharedImage(from:completion:)` | Iterates `NSExtensionItem` attachments; loads first `UTType.image` via `loadItem` |
| | `storeImageData(_:fileName:)` | Writes image file to App Group container; writes metadata to UserDefaults |
| | `setSharedPhotoReadyFlag()` | Sets `sharedPhotoReady = true` in App Group UserDefaults |
| | `openMainApp()` | Opens `timesafari://` via responder chain or `extensionContext.open` |
| | `getFileNameWithExtension(_:newExtension:)` | Helper for PNG fallback filename |
| `ios/App/TimeSafariShareExtension/Info.plist` | — | Declares share-services extension; accepts 1 image max |
| `ios/App/TimeSafariShareExtension/TimeSafariShareExtension.entitlements` | — | Grants App Group `group.app.timesafari.share` |
### Main App Native Layer (Reader)
| File | Method | Responsibility |
|------|--------|----------------|
| `ios/App/App/SharedImageUtility.swift` | `getSharedImageData()` | Read-only: reads file from App Group, returns base64 + fileName; leaves metadata and file intact (Phase 1C) |
| | `hasSharedImage()` | Non-destructive existence check (metadata + file on disk) |
| | `isSharedPhotoReady()` | Reads `sharedPhotoReady` flag |
| | `clearSharedPhotoReadyFlag()` | Removes `sharedPhotoReady` key |
| `ios/App/App/SharedImagePlugin.swift` | `getSharedImage(_:)` | Capacitor bridge to `getSharedImageData()` |
| | `hasSharedImage(_:)` | Capacitor bridge to `hasSharedImage()` |
| `ios/App/App/AppDelegate.swift` | `application(_:didFinishLaunchingWithOptions:)` | Registers `SharedImagePlugin` with retry loop |
| | `registerSharedImagePlugin()` | Manually registers plugin instance on Capacitor bridge |
| | `applicationDidBecomeActive(_:)` | Calls `checkForSharedImageOnActivation()` |
| | `checkForSharedImageOnActivation()` | Checks ready flag, clears it, posts `SharedPhotoReady` NSNotification |
| | `application(_:open:options:)` | Forwards URL opens (including `timesafari://`) to Capacitor |
| `ios/App/App/App.entitlements` | — | Grants App Group `group.app.timesafari.share` |
### JavaScript Layer (Consumer)
| File | Method | Responsibility |
|------|--------|----------------|
| `src/plugins/SharedImagePlugin.ts` | — | Registers Capacitor plugin name `SharedImage` |
| `src/plugins/definitions.ts` | — | TypeScript interface for `getSharedImage` / `hasSharedImage` |
| `src/main.capacitor.ts` | `checkAndStoreNativeSharedImage()` | Calls `SharedImage.getSharedImage()`, stores in temp DB; guarded by `isProcessingSharedImage` lock |
| | `storeSharedImageInTempDB()` | Clears old temp row, inserts base64 data URL into SQLite `temp` table |
| | `checkForSharedImageAndNavigate()` | Checks native share, navigates to `/shared-photo` on success |
| | `handleDeepLink()` | Handles `timesafari://` empty-path URLs from share extension on iOS |
| | `registerDeepLinkListener()` | Registers Capacitor `appUrlOpen` listener |
| `src/views/SharedPhotoView.vue` | `mounted()` / `onRouteQueryChange()` | Loads image from temp DB for display |
| | `loadSharedImage()` | Reads `SHARED_PHOTO_BASE64_KEY` from temp DB; **deletes temp row** after load |
| `src/router/index.ts` | — | Defines `/shared-photo` route |
| `src/libs/util.ts` | `SHARED_PHOTO_BASE64_KEY` | Temp DB key constant (`"shared-photo-base64"`) |
---
## Read / Write / Delete Inventory
### Writes — Shared Image Metadata (App Group UserDefaults)
| File | Method | Keys Written |
|------|--------|--------------|
| `ShareViewController.swift` | `storeImageData(_:fileName:)` | `sharedPhotoFilePath`, `sharedPhotoFileName` |
| `ShareViewController.swift` | `setSharedPhotoReadyFlag()` | `sharedPhotoReady` (= `true`) |
### Writes — Shared Image Files (App Group Container)
| File | Method | Details |
|------|--------|---------|
| `ShareViewController.swift` | `storeImageData(_:fileName:)` | `imageData.write(to:)` at `{containerURL}/{actualFileName}` |
### Reads — Shared Image Metadata (App Group UserDefaults)
| File | Method | Keys Read |
|------|--------|-----------|
| `SharedImageUtility.swift` | `getSharedImageData()` | `sharedPhotoFilePath`, `sharedPhotoFileName` |
| `SharedImageUtility.swift` | `hasSharedImage()` | `sharedPhotoFilePath` |
| `SharedImageUtility.swift` | `isSharedPhotoReady()` | `sharedPhotoReady` |
| `AppDelegate.swift` | `checkForSharedImageOnActivation()` | `sharedPhotoReady` (via `isSharedPhotoReady()`) |
### Reads — Shared Image Files (App Group Container)
| File | Method | Details |
|------|--------|---------|
| `ShareViewController.swift` | `processSharedImage` (URL path) | Reads source image via `Data(contentsOf: url)` from security-scoped URL |
| `SharedImageUtility.swift` | `getSharedImageData()` | `Data(contentsOf: fileURL)` from App Group container |
| `SharedImageUtility.swift` | `hasSharedImage()` | `FileManager.fileExists(atPath:)` only (no data read) |
### Deletes — Shared Image Metadata (App Group UserDefaults)
| File | Method | Keys Removed |
|------|--------|--------------|
| `ShareViewController.swift` | `storeImageData(_:fileName:)` | `sharedPhotoBase64` (legacy cleanup) |
| `SharedImageUtility.swift` | `clearSharedPhotoReadyFlag()` | `sharedPhotoReady` |
| `AppDelegate.swift` | `checkForSharedImageOnActivation()` | `sharedPhotoReady` (via `clearSharedPhotoReadyFlag()`) |
**Removed in Phase 1C** (previously in `SharedImageUtility.getSharedImageData()`):
| Keys / files | Mechanism |
|--------------|-----------|
| `sharedPhotoFilePath` | `userDefaults.removeObject(forKey:)` |
| `sharedPhotoFileName` | `userDefaults.removeObject(forKey:)` |
| Image file at `sharedPhotoFilePath` | `FileManager.removeItem(at:)` |
| `userDefaults.synchronize()` after deletion | Called after metadata/file removal |
### Deletes — Shared Image Files (App Group Container)
| File | Method | Details |
|------|--------|---------|
| `ShareViewController.swift` | `storeImageData(_:fileName:shareId:)` | Removes previous pending share file at prior `sharedPhotoFilePath` before write |
**Removed in Phase 1C** (previously in `SharedImageUtility.getSharedImageData()`):
| Operation | Mechanism |
|-----------|-----------|
| Delete image file after successful read | `FileManager.removeItem(at: fileURL)` |
### Secondary Storage (Post-Native Consumption)
After native read, image data lives in SQLite `temp` table under key `shared-photo-base64`:
| File | Method | Operation |
|------|--------|-----------|
| `main.capacitor.ts` | `storeSharedImageInTempDB()` | **DELETE** old row, then **INSERT OR REPLACE** |
| `SharedPhotoView.vue` | `loadSharedImage()` | **READ** then **DELETE** temp row |
---
## Timing, Delays, Retries, and Polling
| Location | Mechanism | Values | Purpose |
|----------|-----------|--------|---------|
| `AppDelegate.swift` `didFinishLaunching` | Plugin registration retry loop | Initial delay **0.5s**; up to **5** attempts; backoff **0.5s × attempt** | Ensure Capacitor bridge exists before registering `SharedImagePlugin` |
| `main.capacitor.ts` startup | `setTimeout` | **1000ms** (iOS only) | Deferred check for shared image on cold launch |
| `main.capacitor.ts` startup | `setTimeout` | **2000ms** | Deferred registration of `appUrlOpen` deep-link listener |
| `main.capacitor.ts` startup | `setTimeout` | **1000ms** | Log app initialization status |
| `main.capacitor.ts` | `CapacitorApp.addListener("appStateChange")` | On every `isActive === true` | Re-check shared image when app foregrounds |
| `main.capacitor.ts` | `isProcessingSharedImage` flag | Synchronous JS lock | Prevents concurrent `checkAndStoreNativeSharedImage()` calls |
| `main.capacitor.ts` | Comment at line 214 | References polling | **Stale comment**`checkAndStoreNativeSharedImage()` does **not** poll or retry |
**No native polling or retry** exists for reading App Group data. `hasSharedImage()` is exposed but **never called** from application JS code.
---
## Current Startup Detection Points
| # | Layer | Trigger | File | Method | Action |
|---|-------|---------|------|--------|--------|
| 1 | Native | App becomes active (cold start + resume) | `AppDelegate.swift` | `applicationDidBecomeActive``checkForSharedImageOnActivation` | Reads `sharedPhotoReady` flag; clears flag; posts `SharedPhotoReady` NSNotification *(no JS listener)* |
| 2 | JS | Module load + 1000ms delay | `main.capacitor.ts` | `setTimeout``checkForSharedImageAndNavigate` | Calls `SharedImage.getSharedImage()`, stores in temp DB, navigates to `/shared-photo` |
| 3 | JS | App foreground | `main.capacitor.ts` | `appStateChange` listener → `checkForSharedImageAndNavigate` | Same as above |
| 4 | JS | Deep link `timesafari://` | `main.capacitor.ts` | `appUrlOpen``handleDeepLink``checkAndStoreNativeSharedImage` | iOS-only empty-path URL handling; navigates to `/shared-photo` |
| 5 | Native | URL open | `AppDelegate.swift` | `application(_:open:options:)` | Forwards to Capacitor `ApplicationDelegateProxy` (enables #4) |
| 6 | Native | Cold launch plugin setup | `AppDelegate.swift` | `didFinishLaunching``tryRegister` | Registers `SharedImagePlugin` (not a share check, but required for JS reads) |
**Note:** Detection points 14 can all fire for a single share event. Only the JS paths (#24) actually read and consume the image.
---
## Current Deletion Points
### App Group (Native)
| When | File | Method | What is deleted |
|------|------|--------|-----------------|
| Before new share write | `ShareViewController.swift` | `storeImageData` | Previous pending share file at prior `sharedPhotoFilePath` |
| Legacy cleanup on write | `ShareViewController.swift` | `storeImageData` | `sharedPhotoBase64` UserDefaults key |
| On app activation (flag only) | `AppDelegate.swift` | `checkForSharedImageOnActivation` | `sharedPhotoReady` flag |
**Removed in Phase 1C** (no longer deleted on retrieve):
| When | File | Method | What was deleted |
|------|------|--------|------------------|
| On successful read | `SharedImageUtility.swift` | `getSharedImageData` | `sharedPhotoFilePath`, `sharedPhotoFileName`, image file |
### Temp Database (JS)
| When | File | Method | What is deleted |
|------|------|--------|-----------------|
| Before storing new share | `main.capacitor.ts` | `storeSharedImageInTempDB` | Prior `shared-photo-base64` temp row |
| After view loads image | `SharedPhotoView.vue` | `loadSharedImage` | `shared-photo-base64` temp row |
**Important:** Native image file and metadata persist after `getSharedImageData()` (Phase 1C). Cleanup is deferred to a later phase. The `sharedPhotoReady` flag is still cleared independently by `AppDelegate` on activation.
---
## Potential Race Conditions
1. **Multiple JS detection paths, repeatable native read.** `applicationDidBecomeActive`, the 1000ms startup timer, `appStateChange`, and `appUrlOpen` can all invoke `checkAndStoreNativeSharedImage()` close together. Since Phase 1C, `getSharedImageData()` is read-only and returns the same data on every call until a new share overwrites metadata or explicit cleanup is added. The `isProcessingSharedImage` JS lock still reduces duplicate temp-DB writes and navigations.
2. **Deep-link listener registered 2 seconds after mount.** The share extension opens `timesafari://` immediately. If Capacitor does not buffer the launch URL until the `appUrlOpen` listener is registered (at T+2000ms), the deep-link path may be missed on cold start. The 1000ms startup check and `appStateChange` paths partially compensate.
3. **Plugin registration vs. first `getSharedImage()` call.** `SharedImagePlugin` is registered with up to 5 retries starting at T+500ms. A `getSharedImage()` call before registration completes will fail. The 1000ms startup delay usually avoids this, but `appStateChange` can fire earlier.
4. **`sharedPhotoReady` flag cleared before JS reads image.** `AppDelegate.checkForSharedImageOnActivation` clears the flag and posts `SharedPhotoReady`, but no JavaScript code listens for that NSNotification. The flag is therefore a redundant signal; reliance is entirely on file/metadata presence. If file write failed but flag were set, the flag would be cleared with no image available (current code sets flag only after successful `storeImageData`).
5. **`SharedPhotoReady` NSNotification is a dead signal.** Posted in `AppDelegate` but not bridged to Capacitor/JS. All actual consumption happens through JS-initiated `getSharedImage()` calls.
6. **Concurrent share while app is open.** A second share overwrites the App Group file and metadata. If the first share has already been read into temp DB but the user has not yet reached `SharedPhotoView`, the second share can replace native data; navigation refresh via `_refresh` query param handles re-navigation but temp DB overwrite in `storeSharedImageInTempDB` can clobber an in-flight first image.
7. **Extension `completeRequest` timing.** `completeRequest` runs in the `processSharedImage` completion handler after `storeImageData`, flag set, and `openMainApp` — so the file should exist before the extension exits. However, `loadItem` is asynchronous; if the extension process is terminated aggressively by iOS after `completeRequest`, this is generally safe because all writes complete in the callback before completion.
8. **Stale comment implies polling that does not exist.** `handleDeepLink` comments reference internal polling in `checkAndStoreNativeSharedImage`, but no retry loop exists. A single failed read at the wrong moment is not retried on iOS (unlike Android's multi-delay startup checks).
9. **`hasSharedImage()` unused.** A non-destructive pre-check is available natively but JS always calls `getSharedImage()` directly. Since Phase 1C both methods are non-destructive on the native layer.
---
## Share ID Tracking
**Implemented:** 2026-06-23 (Phase 1A)
Phase 1A adds a unique share identifier to the iOS share flow for observability and future reliability work. Existing retrieval and deletion behavior is unchanged.
### Identifier
| Property | Value |
|----------|-------|
| UserDefaults key | `sharedPhotoShareId` |
| Format | `UUID().uuidString` (e.g. `A1B2C3D4-E5F6-7890-ABCD-EF1234567890`) |
| Generated in | `ShareViewController.processSharedImage` when the first image attachment is found |
| Persisted in | `ShareViewController.storeImageData` alongside `sharedPhotoFilePath` and `sharedPhotoFileName` |
### Logging
All log lines use the prefix `[ShareTarget]` and include `shareId=<id>`:
| Event | File | Method | When |
|-------|------|--------|------|
| share received | `ShareViewController.swift` | `processSharedImage` | UUID generated before `loadItem` |
| file stored | `ShareViewController.swift` | `storeImageData` | After successful `imageData.write(to:)` |
| metadata stored | `ShareViewController.swift` | `storeImageData` | After UserDefaults `synchronize()` |
| share retrieved | `SharedImageUtility.swift` | `getSharedImageData` | After successful file read (Phase 1C log format) |
Example log sequence for a single share:
```
[ShareTarget] share received shareId=A1B2C3D4-E5F6-7890-ABCD-EF1234567890
[ShareTarget] file stored shareId=A1B2C3D4-E5F6-7890-ABCD-EF1234567890 originalFilename=vacation.jpg storedFilename=A1B2C3D4-E5F6-7890-ABCD-EF1234567890.jpg
[ShareTarget] metadata stored shareId=A1B2C3D4-E5F6-7890-ABCD-EF1234567890 originalFilename=vacation.jpg storedFilename=A1B2C3D4-E5F6-7890-ABCD-EF1234567890.jpg
[ShareTarget] shareId=A1B2C3D4-E5F6-7890-ABCD-EF1234567890 retrieved
[ShareTarget] shareId=A1B2C3D4-E5F6-7890-ABCD-EF1234567890 left intact after retrieval
```
### Phase 1A Scope (Intentionally Unchanged)
- `getSharedImageData()` still returns only `base64` and `fileName` to JavaScript
- `sharedPhotoShareId` is not deleted on retrieve (cleanup deferred to a later phase)
- `hasSharedImage()`, `isSharedPhotoReady()`, and JS consumption paths are unchanged
- Android code is unchanged
### Write Inventory Addition
| File | Method | Key Written |
|------|--------|-------------|
| `ShareViewController.swift` | `storeImageData(_:fileName:shareId:)` | `sharedPhotoShareId` |
### Read Inventory Addition
| File | Method | Key Read |
|------|--------|----------|
| `SharedImageUtility.swift` | `getSharedImageData()` | `sharedPhotoShareId` (logging only) |
---
## Unique Stored Filenames
**Implemented:** 2026-06-23 (Phase 1B)
Phase 1B eliminates on-disk filename collisions by storing each shared image under a UUID-based filename while preserving the original filename as metadata for consumers.
### On-Disk vs Metadata
| Field | UserDefaults key | Example | Purpose |
|-------|------------------|---------|---------|
| Stored filename | `sharedPhotoFilePath` | `A1B2C3D4-E5F6-7890-ABCD-EF1234567890.jpg` | Unique file in App Group container |
| Original filename | `sharedPhotoFileName` | `vacation-photo.jpg` | Returned to JS as `fileName` |
| Share ID | `sharedPhotoShareId` | `A1B2C3D4-E5F6-7890-ABCD-EF1234567890` | Correlates logs across extension and main app |
Stored filename format: `<shareId>.<extension>`, where extension is taken from the original filename (defaults to `jpg` when absent).
### Implementation
| File | Method | Change |
|------|--------|--------|
| `ShareViewController.swift` | `fileExtension(from:)` | Extracts extension from original filename |
| `ShareViewController.swift` | `storedFileName(shareId:originalFileName:)` | Builds `<shareId>.<ext>` |
| `ShareViewController.swift` | `storeImageData` | Writes to stored filename; saves original in `sharedPhotoFileName` |
| `SharedImageUtility.swift` | `getSharedImageData` | Reads file via `sharedPhotoFilePath`; returns original `sharedPhotoFileName` |
When a new share arrives before the previous one is retrieved, `storeImageData` removes the file at the previous `sharedPhotoFilePath` before writing, preserving single-pending-share semantics.
### Logging (Phase 1B)
Store and retrieve events include all three identifiers:
```
[ShareTarget] file stored shareId=<id> originalFilename=<name> storedFilename=<shareId>.<ext>
[ShareTarget] metadata stored shareId=<id> originalFilename=<name> storedFilename=<shareId>.<ext>
[ShareTarget] shareId=<id> retrieved
[ShareTarget] shareId=<id> left intact after retrieval
```
### Phase 1B Scope (Intentionally Unchanged)
- `getSharedImageData()` still returns only `base64` and original `fileName` to JavaScript
- Android code is unchanged
---
## Non-Destructive Retrieval
**Implemented:** 2026-06-24 (Phase 1C)
Phase 1C makes native shared-content retrieval read-only. `getSharedImageData()` and `SharedImagePlugin.getSharedImage()` no longer delete App Group metadata or image files after a successful read. Explicit cleanup is deferred to a later phase.
### Behavior Change
| Aspect | Before Phase 1C | After Phase 1C |
|--------|-----------------|----------------|
| `sharedPhotoFilePath` after retrieve | Removed | Retained |
| `sharedPhotoFileName` after retrieve | Removed | Retained |
| `sharedPhotoShareId` after retrieve | Retained (since Phase 1A) | Retained |
| Image file after retrieve | Deleted | Retained |
| Return value to JS | `{ base64, fileName }` | Unchanged |
| Repeat `getSharedImage()` calls | Return `null` after first success | Return same data until overwritten or cleaned up |
### Logging
After a successful read:
```
[ShareTarget] shareId=<id> retrieved
[ShareTarget] shareId=<id> left intact after retrieval
```
### Removed Deletion Paths
All removal logic was in `SharedImageUtility.getSharedImageData()`:
| # | What was deleted | Code removed |
|---|------------------|--------------|
| 1 | `sharedPhotoFilePath` UserDefaults key | `userDefaults.removeObject(forKey: sharedPhotoFilePathKey)` |
| 2 | `sharedPhotoFileName` UserDefaults key | `userDefaults.removeObject(forKey: sharedPhotoFileNameKey)` |
| 3 | Image file at `{container}/{sharedPhotoFilePath}` | `FileManager.default.removeItem(at: fileURL)` |
| 4 | Post-deletion UserDefaults flush | `userDefaults.synchronize()` after removals |
`SharedImagePlugin.getSharedImage(_:)` delegated to `getSharedImageData()` and had no independent deletion logic. Comment updated to reflect read-only behavior.
### Phase 1C Scope (Intentionally Unchanged)
- No new cleanup or purge APIs added
- `clearSharedPhotoReadyFlag()` and share-extension write-side file removal unchanged
- JS temp DB deletion in `main.capacitor.ts` and `SharedPhotoView.vue` unchanged
- Android code unchanged
---
## Deterministic Startup Plugin Readiness
**Implemented:** 2026-06-26 (Phase 2A)
Phase 2A removes the iOS startup race between native `SharedImage` plugin
registration and the first JS shared-image check. All changes are confined to
`src/main.capacitor.ts`; no Swift code changed.
### Race condition removed
Previously the initial iOS shared-image check ran on a fixed timer:
```ts
const checkDelays = ... : [1000]; // iOS
checkDelays.forEach((delay) => setTimeout(() => checkForSharedImageAndNavigate(), delay));
```
The native `SharedImagePlugin` is registered asynchronously by
`AppDelegate.didFinishLaunchingWithOptions` with up to 5 retries starting at
T+500ms (`AppDelegate.swift:2140`). The fixed 1000ms JS delay only *assumed*
registration had completed by then. When registration was slow (or the WebView
booted unusually fast), the first `checkForSharedImageAndNavigate()` could call
`SharedImage.getSharedImage()` before the native plugin existed, the call would
throw, and the cold-start share could be missed until a later `appStateChange`.
This corresponds to race condition #3 in *Potential Race Conditions* above.
### How plugin readiness is now determined
The fixed 1000ms iOS delay is replaced with an explicit, deterministic wait
(`waitForSharedImagePluginReady()` in `main.capacitor.ts`):
- The plugin is probed with a lightweight, read-only `SharedImage.hasSharedImage()`
call. A successful resolution proves the native plugin instance is registered
and reachable from JS. `hasSharedImage()` does not consume or mutate the pending
share (non-destructive since Phase 1C), so probing is side-effect free.
- If the probe throws (plugin not yet registered), it retries within a bounded
budget: `STARTUP_PLUGIN_MAX_ATTEMPTS = 10` attempts spaced
`STARTUP_PLUGIN_RETRY_DELAY_MS = 300` ms apart (~3s ceiling, covering the
native registration window). No arbitrary sleep is used to *assume* readiness;
the delay is only the inter-retry backoff while polling for actual availability.
- The very first `checkForSharedImageAndNavigate()` runs only after the probe
succeeds. If the budget is exhausted (should not happen in practice), the check
is still attempted once as a best-effort fallback so behavior is never worse
than the previous fixed-delay path, and `appStateChange` retries on the next
activation.
### Temporary diagnostics
The retry sequence emits `[ShareTarget]` console diagnostics, consistent with the
existing TEMPORARY SHARE TARGET DIAGNOSTICS convention:
```
[ShareTarget] Startup shared-image check waiting for SharedImage plugin
[ShareTarget] SharedImage plugin ready after N attempt(s)
[ShareTarget] Startup shared-image check giving up after N attempt(s)
```
### Phase 2A Scope (Intentionally Unchanged)
The retry/readiness logic applies **only** to the initial startup shared-image
check. The following are deliberately untouched:
- `appStateChange` handling (`CapacitorApp.addListener("appStateChange", ...)`)
- `appUrlOpen` handling (`handleDeepLink`, `registerDeepLinkListener`)
- Router navigation to `/shared-photo`
- Share processing (`checkAndStoreNativeSharedImage`, `storeSharedImageInTempDB`)
- Android startup behavior (still `[500, 1500, 3000]` ms multi-delay checks)
- All native Swift code, including the `AppDelegate` plugin-registration retry
Because readiness is now confirmed by an actual plugin response rather than a
timer, the startup check no longer depends on registration timing, while every
other detection path keeps its previous semantics as redundant backstops.
---
## Configuration References
| Resource | Value |
|----------|-------|
| App Group ID | `group.app.timesafari.share` |
| URL scheme | `timesafari://` |
| Extension bundle ID | `app.timesafari.TimeSafariShareExtension` |
| Main app bundle ID | `app.timesafari` |
| Capacitor plugin name | `SharedImage` |
| Temp DB key | `shared-photo-base64` (`SHARED_PHOTO_BASE64_KEY`) |
| Route | `/shared-photo` |

View File

@@ -0,0 +1,515 @@
# iOS Share-Target Launch & Deep-Link Flow Audit
**Date:** 2026-06-26 15:32:14 PST
**Scope:** iOS Share Extension launch path and `timesafari://` deep-link handling only.
**Status:** Read-only audit. No code was modified. **No code changes are recommended.**
This document traces the complete execution path that begins when the iOS
Share Extension calls `application.open("timesafari://")` and ends with
navigation to `/shared-photo`. All references cite file, method, and
approximate line numbers as of the audit date.
### Files in scope
| File | Role |
| --- | --- |
| `ios/App/TimeSafariShareExtension/ShareViewController.swift` | Share Extension: stores image to App Group, opens `timesafari://` |
| `ios/App/App/AppDelegate.swift` | Native app delegate: lifecycle + URL open proxy |
| `ios/App/App/SharedImagePlugin.swift` | Capacitor plugin bridge (`SharedImage`) |
| `ios/App/App/SharedImageUtility.swift` | App Group read/write helpers + ready flag |
| `src/main.capacitor.ts` | JS bootstrap, deep-link listener, shared-image checks, navigation |
| `src/main.common.ts` | `initializeApp()` — Vue app + router construction |
| `src/router/index.ts` | Router creation, `/shared-photo` route |
| `src/libs/capacitor/app.ts` | Type-safe wrapper around `@capacitor/app` listeners |
| `src/plugins/SharedImagePlugin.ts` | JS `registerPlugin("SharedImage")` |
| `capacitor.config.ts` | `appUrlOpen` handler config for `timesafari://*` |
---
## 1. Cold-start launch path
"Cold start" = the main app process is **not** running when the user taps Share.
### Execution order
1. **Share Extension `viewDidLoad()`**
`ShareViewController.swift:47` → calls `processAndOpenApp()` (`:64`).
2. **`processAndOpenApp()`** — `ShareViewController.swift:70`
Reads `extensionContext.inputItems`, then calls `processSharedImage(...)` (`:97`).
3. **`processSharedImage(...)`** — `ShareViewController.swift:148`
Loads the first image attachment, then `storeImageData(...)` (`:245`).
4. **`storeImageData(...)`** — `ShareViewController.swift:292`
Writes the image file into the App Group container and writes metadata keys
(`sharedPhotoFilePath`, `sharedPhotoFileName`, `sharedPhotoShareId`) to
`UserDefaults(suiteName: "group.app.trentlarson.timesafari.share")` (`:340347`).
5. **`setSharedPhotoReadyFlag()`** — `ShareViewController.swift:129` (called at `:108`)
Sets `sharedPhotoReady = true` in the App Group UserDefaults (`:140`).
6. **`openMainApp()`** — `ShareViewController.swift:356` (called at `:110`)
Builds `URL(string: "timesafari://")` (`:362`), walks the responder chain to
find a `UIApplication`, and calls `application.open(url, ...)` (`:373`).
Fallback: `extensionContext?.open(url, ...)` (`:383`).
7. **`context.completeRequest(...)`** — `ShareViewController.swift:119`
Extension finishes; iOS hands the URL to the main app, launching the process.
8. **Main app process launches → `AppDelegate.application(_:didFinishLaunchingWithOptions:)`**
`AppDelegate.swift:11`.
- Sets `UNUserNotificationCenter.delegate` (`:13`).
- Schedules `SharedImagePlugin` registration on the main queue starting at
**T+0.5s**, with up to 5 retries at increasing delays (`:2140`,
`registerSharedImagePlugin()` at `:46`). Registration requires the
Capacitor bridge to exist (`:4851`).
- **Note:** `launchOptions` is received but is **never inspected** for a launch
URL. AppDelegate does not read `launchOptions[.url]`.
9. **Capacitor native bridge boots** (`CAPBridgeViewController` as `window.rootViewController`).
The bridge loads the WKWebView and the JS bundle.
10. **`AppDelegate.application(_:open:options:)`** — `AppDelegate.swift:133`
When iOS delivers `timesafari://`, this proxies straight to
`ApplicationDelegateProxy.shared.application(app, open: url, options:)` (`:138`).
Capacitor's proxy is responsible for emitting the `appUrlOpen` event to JS —
**but only to listeners that are already registered** (see §5).
11. **JS startup — `src/main.capacitor.ts` executes top-to-bottom on bundle load:**
- Logging banner (`:4748`).
- `const app = initializeApp();` (`:50`) → `src/main.common.ts:33`
builds the Vue app, Pinia, axios, and **`app.use(router)`** (`main.common.ts:39`).
The router itself is created at module import time in
`src/router/index.ts:320` (`createRouter` with `createWebHistory("/")`).
- `new DeepLinkHandler(router)` (`main.capacitor.ts:59`).
- `app.mount("#app")` (`main.capacitor.ts:462`).
- **Startup shared-image timer scheduled:** iOS uses `[1000]`ms delay
(`:474483`) → `checkForSharedImageAndNavigate()` at **T+1000ms**.
- **`appStateChange` listener registered** (`:491496`).
- **Deep-link listener registration scheduled** via `setTimeout(..., 2000)`
(`:500510`) → `registerDeepLinkListener()` at **T+2000ms**.
12. **`registerDeepLinkListener()`** — `main.capacitor.ts:298`
Awaits `router.isReady()` (`:322`), then
`CapacitorApp.addListener("appUrlOpen", handleDeepLink)` (`:329`).
This is the **only** `appUrlOpen` registration in the codebase, and it occurs
~2 seconds after mount.
### Cold-start order summary
```
ShareViewController.viewDidLoad
→ processAndOpenApp → processSharedImage → storeImageData (App Group file + metadata)
→ setSharedPhotoReadyFlag (sharedPhotoReady = true)
→ openMainApp → application.open("timesafari://")
→ completeRequest
AppDelegate.didFinishLaunchingWithOptions (launchOptions URL ignored)
→ schedules SharedImagePlugin registration (T+0.5s, ≤5 retries)
Capacitor bridge + WKWebView boot → JS bundle loads
main.capacitor.ts (top-level):
initializeApp() → router created/used → DeepLinkHandler → app.mount("#app")
→ schedule startup check (T+1000ms)
→ register appStateChange listener
→ schedule appUrlOpen registration (T+2000ms)
AppDelegate.application(_:open:) → ApplicationDelegateProxy (appUrlOpen emitted)
applicationDidBecomeActive → checkForSharedImageOnActivation (native flag path)
```
**Key cold-start fact:** because `application.open("timesafari://")` is delivered
during/just after process launch, the Capacitor `appUrlOpen` event fires **before**
the JS `appUrlOpen` listener is registered (registration is at T+2000ms). On cold
start, the successful navigation is therefore driven by the **T+1000ms startup
timer** (and/or `appStateChange`), not by `appUrlOpen`. See §6 and §7.
---
## 2. Warm-start launch path
"Warm start" = the main app process is already running (foreground or background)
when the user taps Share.
1. **Share Extension** runs the identical sequence as §1 steps 17
(`storeImageData``setSharedPhotoReadyFlag``openMainApp`
`application.open("timesafari://")``completeRequest`).
2. **iOS resumes the existing app process** (no new launch, no
`didFinishLaunchingWithOptions`).
3. **`AppDelegate.application(_:open:options:)`** — `AppDelegate.swift:133`
Proxies to `ApplicationDelegateProxy.shared.application(...)` (`:138`).
Because the JS `appUrlOpen` listener was registered during the earlier launch
(T+2000ms after the first mount), Capacitor delivers the event to JS.
4. **`AppDelegate.applicationDidBecomeActive`** — `AppDelegate.swift:77`
Also fires on resume:
- re-sets the notification delegate (`:81`),
- calls `checkForSharedImageOnActivation()` (`:84`).
`checkForSharedImageOnActivation()` (`:117`) reads `isSharedPhotoReady()`
(`SharedImageUtility.swift:183`), clears the flag (`:121`), and posts the
`SharedPhotoReady` NSNotification (`:125`). **No JS code listens for that
NSNotification** (see §4 / §7) — it is a dead signal.
5. **JS `appUrlOpen` → `handleDeepLink`**`main.capacitor.ts:194`
- `url === "timesafari://"` matches the empty-path branch (`:201`).
- On iOS native (`:203207`), calls `checkAndStoreNativeSharedImage()` (`:216`).
6. **`checkAndStoreNativeSharedImage()`** — `main.capacitor.ts:131`
- Guards against re-entrancy via `isProcessingSharedImage` (`:136`, `:143`).
- Calls `SharedImage.getSharedImage()` (`:159`) → native
`SharedImagePlugin.getSharedImage` (`SharedImagePlugin.swift:43`) →
`SharedImageUtility.getSharedImageData()` (`SharedImageUtility.swift:51`)
which reads the App Group file and returns `{ base64, fileName }`.
- On success, `storeSharedImageInTempDB(...)` (`main.capacitor.ts:72`) writes
the data URL into the SQLite `temp` table under `SHARED_PHOTO_BASE64_KEY`.
7. **Navigation to `/shared-photo`**`main.capacitor.ts:218248`
- `await router.isReady()` (`:224`).
- If already on `/shared-photo`, `router.replace(...)` with a `_refresh`
timestamp (`:234`); otherwise `router.push({ path: "/shared-photo", query: { fileName } })`
(`:239`).
### Warm-start callback chain
```
ShareViewController.openMainApp → application.open("timesafari://") → completeRequest
iOS resumes running process
AppDelegate.application(_:open:) → ApplicationDelegateProxy ── emits appUrlOpen ──┐
AppDelegate.applicationDidBecomeActive → checkForSharedImageOnActivation │
(reads + clears sharedPhotoReady, posts SharedPhotoReady NSNotification = no JS listener)
JS appUrlOpen listener (registered earlier) ←───────────────────────────────────────┘
→ handleDeepLink (empty-path branch)
→ checkAndStoreNativeSharedImage
→ SharedImage.getSharedImage → SharedImageUtility.getSharedImageData (App Group file)
→ storeSharedImageInTempDB (SQLite temp table)
→ router.isReady → router.push/replace("/shared-photo")
```
In parallel, the `appStateChange` listener (`main.capacitor.ts:491`) also fires
on `isActive` and independently calls `checkForSharedImageAndNavigate()`. Both
paths converge on the same `isProcessingSharedImage` lock and the same
`/shared-photo` navigation.
---
## 3. appUrlOpen audit
### Registrations
There is exactly **one** runtime registration of `appUrlOpen` in the codebase:
- **`main.capacitor.ts:329`** inside `registerDeepLinkListener()`:
```ts
const listenerHandle = await CapacitorApp.addListener("appUrlOpen", handleDeepLink);
```
(`CapacitorApp` = `@capacitor/app`, imported at `main.capacitor.ts:32`.)
Supporting / non-runtime references:
- `capacitor.config.ts:1119` declares the `App.appUrlOpen` handler for
`timesafari://*` with `autoVerify: true` (config, not a JS listener).
- `src/libs/capacitor/app.ts:3235, 4259` is a typed wrapper exposing
`addListener("appUrlOpen", ...)`, but `main.capacitor.ts` calls
`@capacitor/app` directly, **not** this wrapper.
### When it is registered relative to startup
- Scheduled by `setTimeout(..., 2000)` at `main.capacitor.ts:500`, i.e.
**~2000 ms after `app.mount("#app")`** (`:462`).
- Inside `registerDeepLinkListener()`, registration additionally waits for
`await router.isReady()` (`:322`) before calling `addListener` (`:329`).
### Handlers that execute because of it
- **`handleDeepLink(data)`** — `main.capacitor.ts:194` is the only handler.
### Calls made by the handler
- **`handleDeepLink`** (`:194`)
- **`checkAndStoreNativeSharedImage()`** (`:216`) — for empty-path
`timesafari://` / `timesafari:///` on iOS native (`:201207`).
- **`router.isReady()`** (`:224`), then **`router.replace`** (`:234`) or
**`router.push`** (`:239`) → navigation to `/shared-photo`.
- For non-empty deep links: `router.isReady()` (`:264`) then
`deepLinkHandler.handleDeepLink(url)` (`:269`) — the `DeepLinkHandler` class
instance (`:59`). (Empty-path share URLs never reach this branch.)
`handleDeepLink` is **not** the same function as `deepLinkHandler.handleDeepLink`
(`src/services/deepLinks.ts`); the module-level function wraps the class method.
### Call graph (appUrlOpen)
```
CapacitorApp.addListener("appUrlOpen", handleDeepLink) [main.capacitor.ts:329]
│ (fires on timesafari:// open, warm start only in practice — see §6)
handleDeepLink(data) [:194]
├─ if url == "timesafari://" / "timesafari:///" and iOS native [:201207]
│ └─ checkAndStoreNativeSharedImage() [:216 → :131]
│ └─ SharedImage.getSharedImage() [:159]
│ └─ (native) getSharedImageData() [SharedImageUtility.swift:51]
│ └─ storeSharedImageInTempDB() [:177 → :72]
│ └─ router.isReady() [:224]
│ └─ router.replace / router.push → /shared-photo [:234 / :239]
└─ else (non-empty deep link)
└─ router.isReady() [:264]
└─ deepLinkHandler.handleDeepLink(url) [:269]
```
---
## 4. Startup / shared-image detection audit
Every place the app checks for a shared image, and when each runs:
| # | Mechanism | Location | When it executes | Cold start? | Warm start? |
| --- | --- | --- | --- | --- | --- |
| A | **Startup timer** `setTimeout(..., 1000)` → `checkForSharedImageAndNavigate()` | `main.capacitor.ts:474483` (iOS delays `[1000]`) | ~1000 ms after JS bundle loads / mount | **Yes** (primary cold-start path) | Only if bundle reloaded (normally no) |
| B | **`appStateChange` listener** → `checkForSharedImageAndNavigate()` | `main.capacitor.ts:491496` | Every time app becomes active (`isActive === true`) | Yes (initial activation can fire) | **Yes** (primary on resume) |
| C | **`appUrlOpen` listener** → `handleDeepLink` → `checkAndStoreNativeSharedImage()` | `main.capacitor.ts:329`, handler `:194/:216` | On `timesafari://` open, **only if listener already registered** (T+2000ms) | Usually **No** (URL arrives before listener) | **Yes** |
| D | **Native `applicationDidBecomeActive`** → `checkForSharedImageOnActivation()` | `AppDelegate.swift:77, 117` | Every activation (launch + resume) | Yes | Yes |
| E | **Native ready-flag read** `isSharedPhotoReady()` / `clearSharedPhotoReadyFlag()` | `SharedImageUtility.swift:183, 195` (called from D) | Inside D | Yes | Yes |
| F | **`SharedPhotoReady` NSNotification** posted | `AppDelegate.swift:125` | Inside D, when flag was set | Yes | Yes |
### Detail per mechanism
- **A — JS startup timer.** `main.capacitor.ts:474483`. iOS uses a single
`[1000]` ms delay (Android uses `[500, 1500, 3000]`). Calls
`checkForSharedImageAndNavigate()` (`:353`), which calls
`checkAndStoreNativeSharedImage()` (`:423`) and then pushes/replaces
`/shared-photo` (`:439449`). This is the mechanism that actually carries
cold-start shares to `/shared-photo`.
- **B — `appStateChange`.** `main.capacitor.ts:491`. Fires on every transition to
active. Calls the same `checkForSharedImageAndNavigate()`. Primary warm-start /
resume detector and a backstop for cold start.
- **C — `appUrlOpen`.** Registered at `main.capacitor.ts:329` (T+2000ms after
mount). Handler `handleDeepLink` (`:194`). Effective only when the listener is
already registered when the URL arrives — i.e. warm starts.
- **D — Native `applicationDidBecomeActive`.** `AppDelegate.swift:77`. Calls
`checkForSharedImageOnActivation()` (`:117`).
- **E — ready flag.** `checkForSharedImageOnActivation()` reads
`SharedImageUtility.isSharedPhotoReady()` (`:119` → `SharedImageUtility.swift:183`)
and clears it via `clearSharedPhotoReadyFlag()` (`:121` →
`SharedImageUtility.swift:195`). The flag is **set** by the extension at
`ShareViewController.swift:140`.
- **F — `SharedPhotoReady` NSNotification.** Posted at `AppDelegate.swift:125`.
**No JavaScript or Capacitor bridge code observes this notification anywhere in
the repo** (only doc references and the post site exist). It is therefore a
dead/no-op signal as far as JS navigation is concerned.
### Polling / retry logic
- **JS retry:** No active polling loop inside `checkAndStoreNativeSharedImage()`.
The code comments at `main.capacitor.ts:213214` mention "polling internally,"
but the implementation (`:131192`) makes a **single** `getSharedImage()` call.
The only "retry-like" behavior on the JS side is the **multiple invocation
surfaces** (A startup timer, B appStateChange, C appUrlOpen), all gated by the
`isProcessingSharedImage` lock (`:62, :136, :143`).
- **Native retry:** `AppDelegate.swift:2140` retries **plugin registration**
(not image detection) up to 5 times starting at T+0.5s.
---
## 5. Native launch information
### Does AppDelegate receive the launch URL before JavaScript is initialized?
**No — the AppDelegate does not capture the launch URL at all.**
- `AppDelegate.application(_:didFinishLaunchingWithOptions:)`
(`AppDelegate.swift:11`) receives `launchOptions`, but the body
(`:1343`) **never reads `launchOptions[.url]`** or otherwise extracts a launch
URL. It only configures notifications and schedules plugin registration.
- The only URL entry point is `AppDelegate.application(_:open:options:)`
(`AppDelegate.swift:133`), which immediately forwards to
`ApplicationDelegateProxy.shared.application(app, open: url, options:)` (`:138`)
with **no local storage** of the URL. Capacitor's proxy owns the URL from here.
### Where is it stored?
- It is **not** stored in the app's own native code. Whatever buffering exists is
internal to Capacitor's `ApplicationDelegateProxy` / `@capacitor/app` plugin.
The app code does not call `App.getLaunchUrl()` anywhere (only referenced in
docs at `doc/native-share-target-implementation.md:436`).
- The **share payload** (not the URL) is durably stored by the extension in the
App Group container: the image file plus metadata keys at
`ShareViewController.swift:340347`, and the `sharedPhotoReady` boolean at
`:140`. This payload is what the JS side later reads via
`SharedImage.getSharedImage()`.
### Is the URL forwarded to JS?
- Only through Capacitor's `appUrlOpen` event, and only to listeners present at
emit time. The single JS listener is registered at
`main.capacitor.ts:329`, **~2000 ms after mount**.
### Can the launch URL be lost before listeners are registered?
- **Yes, the `appUrlOpen` event can be lost on cold start.** Because the URL is
delivered through `application(_:open:)` during/just after launch, and the JS
listener is registered at T+2000ms (`:500`), an event emitted before that point
will have no JS listener — unless Capacitor buffers the launch URL until a
listener attaches. The app code does not rely on (or verify) such buffering;
there is no `getLaunchUrl()` call to recover a missed event.
- **The share payload itself is NOT lost.** Because the image and metadata persist
in the App Group container, the cold-start startup timer (mechanism A,
`main.capacitor.ts:474`) and `appStateChange` (mechanism B, `:491`) can still
retrieve it via `getSharedImage()` independent of whether the `appUrlOpen`
event was delivered. The only thing at risk is the **URL event/signal**, not the
data.
### Complete native-launch flow
```
Extension writes App Group file + metadata + sharedPhotoReady=true [ShareViewController.swift:340,140]
Extension: application.open("timesafari://") [ShareViewController.swift:373]
iOS launches/resumes app
├─ didFinishLaunchingWithOptions(launchOptions) [AppDelegate.swift:11] ← launchOptions URL NOT read
├─ application(_:open:options:) [AppDelegate.swift:133] → ApplicationDelegateProxy (Capacitor buffers/emits appUrlOpen)
└─ applicationDidBecomeActive [AppDelegate.swift:77] → checkForSharedImageOnActivation [:117]
→ isSharedPhotoReady [:119] → clear flag [:121] → post SharedPhotoReady [:125] (no JS listener)
JS bundle loads later → appUrlOpen listener attaches at T+2000ms [main.capacitor.ts:329]
```
---
## 6. Timing analysis
`T0` = moment the JS bundle begins executing / `app.mount("#app")`
(`main.capacitor.ts:462`). Native launch precedes T0.
### Cold start timeline
| Time | Actor | Event | Reference |
| --- | --- | --- | --- |
| pre-launch | Extension | write file + metadata + `sharedPhotoReady=true`; `open("timesafari://")`; `completeRequest` | `ShareViewController.swift:340,140,373,119` |
| launch | Native | `didFinishLaunchingWithOptions` (launch URL ignored) | `AppDelegate.swift:11` |
| ~launch | Native | `application(_:open:)` → ApplicationDelegateProxy → (Capacitor) `appUrlOpen` emitted | `AppDelegate.swift:133` |
| launch +0.5s..2.5s | Native | `SharedImagePlugin` registration (≤5 retries) | `AppDelegate.swift:2140` |
| ~launch | Native | `applicationDidBecomeActive` → `checkForSharedImageOnActivation` → clear flag + post `SharedPhotoReady` (dead) | `AppDelegate.swift:77,117,125` |
| T0 | JS | bundle executes: `initializeApp`, router created/used, `DeepLinkHandler`, `app.mount` | `main.capacitor.ts:50,59,462`; `main.common.ts:39`; `router/index.ts:320` |
| T0 | JS | register `appStateChange` listener | `main.capacitor.ts:491` |
| T0 + ~1000ms | JS | **startup timer** → `checkForSharedImageAndNavigate` → `getSharedImage` → push `/shared-photo` | `main.capacitor.ts:474483,353,423,449` |
| T0 + ~2000ms | JS | `registerDeepLinkListener` → `await router.isReady` → `addListener("appUrlOpen")` | `main.capacitor.ts:500,322,329` |
```
Extension → openMainApp → AppDelegate(launch) → Capacitor bridge → JS bootstrap (T0)
→ router ready → [appUrlOpen registered @ T0+2000ms]
→ startup shared-image check @ T0+1000ms ──► getSharedImage ──► /shared-photo
→ applicationDidBecomeActive (native flag path, no JS effect)
```
**Cold-start race conditions / ordering dependencies:**
1. **`appUrlOpen` arrives before its listener exists.** The URL is delivered at
launch, but the listener attaches at T0+2000ms (`:500`/`:329`). Unless
Capacitor buffers the launch URL, the `appUrlOpen` path does not fire on cold
start. Cold-start success relies on the **T0+1000ms startup timer** instead.
2. **Plugin registration vs. first `getSharedImage()`.** Plugin registration runs
T+0.5s..~2.5s (`AppDelegate.swift:2140`); the startup `getSharedImage()` call
is at ~T0+1000ms. If the bridge/plugin is not yet registered when JS calls
`getSharedImage()`, the call throws and is caught
(`main.capacitor.ts:160167`), returning `{ success: false }`. Recovery then
depends on a later `appStateChange` firing.
3. **Native flag cleared with no JS consumer.** `applicationDidBecomeActive`
clears `sharedPhotoReady` and posts `SharedPhotoReady` (`AppDelegate.swift:121,125`),
but no JS listens. Clearing the flag has no effect on JS navigation because JS
reads the **file/metadata**, not the flag — so this does not cause loss, but
the posted notification is inert.
### Warm start timeline
| Time | Actor | Event | Reference |
| --- | --- | --- | --- |
| t | Extension | write file + metadata + flag; `open("timesafari://")`; `completeRequest` | `ShareViewController.swift:340,140,373,119` |
| t | Native | `application(_:open:)` → ApplicationDelegateProxy → `appUrlOpen` (listener already attached) | `AppDelegate.swift:133`; `main.capacitor.ts:329` |
| t | Native | `applicationDidBecomeActive` → clear flag + post `SharedPhotoReady` (dead) | `AppDelegate.swift:77,121,125` |
| t (≈same) | JS | `appStateChange(isActive)` → `checkForSharedImageAndNavigate` | `main.capacitor.ts:491` |
| t (≈same) | JS | `appUrlOpen` → `handleDeepLink` → `checkAndStoreNativeSharedImage` | `main.capacitor.ts:194,216` |
| t+ε | JS | `getSharedImage` → store temp DB → `router.push/replace("/shared-photo")` | `main.capacitor.ts:159,177,234/239` |
```
Extension → appUrlOpen (listener present) ─┐
├─► handleDeepLink / checkForSharedImageAndNavigate
appStateChange(isActive) ──────────────────┘ → getSharedImage → /shared-photo
```
**Warm-start race conditions / ordering dependencies:**
1. **Duplicate triggers.** `appUrlOpen` (C) and `appStateChange` (B) fire at
nearly the same time, both calling `checkAndStoreNativeSharedImage()`. The
`isProcessingSharedImage` boolean lock (`main.capacitor.ts:62,136,143`)
prevents concurrent processing, but it is a simple non-reentrant flag: the
second caller returns `{ success: false }` immediately and does not navigate,
so navigation is driven by whichever caller wins. Because the lock is released
synchronously at the end of each path, ordering determines which trigger
performs the navigation.
2. **Read-only native retrieval.** `getSharedImageData()`
(`SharedImageUtility.swift:51`) leaves the file/metadata intact after reading
(`:7576`), so repeated reads from B and C return the same data rather than one
"consuming" the other.
---
## 7. Final summary
(No code changes recommended — answers only.)
1. **What mechanism actually causes successful warm-start shares to navigate to
`/shared-photo`?**
The **JS `appUrlOpen` listener** (`main.capacitor.ts:329`) firing
`handleDeepLink` (`:194`), and/or the **`appStateChange` listener** (`:491`),
each calling `checkAndStoreNativeSharedImage()` → `SharedImage.getSharedImage()`
→ `router.push/replace("/shared-photo")`. On a warm start the `appUrlOpen`
listener already exists, so the deep-link path is available; `appStateChange`
is a redundant parallel trigger. Both converge through the
`isProcessingSharedImage` lock onto the same navigation.
2. **What mechanism is supposed to cause successful cold-start shares to navigate
to `/shared-photo`?**
The **JS startup timer** at `main.capacitor.ts:474483` (iOS `[1000]` ms) →
`checkForSharedImageAndNavigate()` (`:353`) →
`checkAndStoreNativeSharedImage()` (`:423`) → `getSharedImage()` (reads the App
Group file/metadata persisted by the extension) → `router.push("/shared-photo")`
(`:449`). `appStateChange` (`:491`) acts as a backstop. This path does **not**
depend on the `appUrlOpen` event, because the `appUrlOpen` listener is not
registered until ~T0+2000ms (`:500`), after the launch URL has already been
delivered.
3. **Are those mechanisms the same or different?**
**Different.**
- Warm start: driven primarily by the **`appUrlOpen` deep-link event**
(`handleDeepLink`, `:194`/`:216`), with `appStateChange` as parallel backup.
- Cold start: driven by the **startup `setTimeout` poll** (`:474`) /
`appStateChange` (`:491`) calling `checkForSharedImageAndNavigate()`.
They share the same downstream code (`checkAndStoreNativeSharedImage` →
`getSharedImage` → router navigation) but are entered through **different
triggers**, because the `appUrlOpen` event is unavailable during cold start.
4. **Is there any point where a launch URL or launch signal could be lost before
JavaScript is ready?**
**Yes — the `appUrlOpen` URL event can be lost on cold start.** The launch URL
is delivered to `AppDelegate.application(_:open:)` (`AppDelegate.swift:133`)
and proxied into Capacitor at process launch, but the JS `appUrlOpen` listener
is not registered until ~2000 ms after mount (`main.capacitor.ts:500,329`).
If Capacitor does not buffer the launch URL until that listener attaches, the
`appUrlOpen` event is dropped. Additionally, the native
`SharedPhotoReady` NSNotification (`AppDelegate.swift:125`) is posted with **no
JS/bridge listener**, so that signal is always lost.
**However, the share payload (image + metadata in the App Group container,
`ShareViewController.swift:340347`) is durable and is not lost**; it is
recovered by the startup timer / `appStateChange` calling
`getSharedImage()`, which is why cold-start shares can still reach
`/shared-photo` despite the `appUrlOpen` event being unavailable.

View File

@@ -18,6 +18,7 @@
C86585DF2ED456DE00824752 /* TimeSafariShareExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = C86585D52ED456DE00824752 /* TimeSafariShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
C8C56E142EE0474B00737D0E /* SharedImageUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8C56E132EE0474B00737D0E /* SharedImageUtility.swift */; };
C8C56E162EE064CB00737D0E /* SharedImagePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8C56E152EE064CA00737D0E /* SharedImagePlugin.swift */; };
C8C56E182EE0700A00737D0E /* AppBridgeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8C56E172EE0700A00737D0E /* AppBridgeViewController.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -59,6 +60,7 @@
C86585E52ED4577F00824752 /* App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = App.entitlements; sourceTree = "<group>"; };
C8C56E132EE0474B00737D0E /* SharedImageUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedImageUtility.swift; sourceTree = "<group>"; };
C8C56E152EE064CA00737D0E /* SharedImagePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedImagePlugin.swift; sourceTree = "<group>"; };
C8C56E172EE0700A00737D0E /* AppBridgeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppBridgeViewController.swift; sourceTree = "<group>"; };
E2E9297D5D02C549106C77F9 /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
EAEC6436E595F7CD3A1C9E96 /* Pods-App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.debug.xcconfig"; path = "Target Support Files/Pods-App/Pods-App.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -74,18 +76,7 @@
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
C86585D62ED456DE00824752 /* TimeSafariShareExtension */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
C86585E32ED456DE00824752 /* PBXFileSystemSynchronizedBuildFileExceptionSet */,
);
explicitFileTypes = {
};
explicitFolders = (
);
path = TimeSafariShareExtension;
sourceTree = "<group>";
};
C86585D62ED456DE00824752 /* TimeSafariShareExtension */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (C86585E32ED456DE00824752 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = TimeSafariShareExtension; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
@@ -138,6 +129,7 @@
504EC3061FED79650016851F /* App */ = {
isa = PBXGroup;
children = (
C8C56E172EE0700A00737D0E /* AppBridgeViewController.swift */,
C8C56E152EE064CA00737D0E /* SharedImagePlugin.swift */,
C8C56E132EE0474B00737D0E /* SharedImageUtility.swift */,
C86585E52ED4577F00824752 /* App.entitlements */,
@@ -357,6 +349,7 @@
buildActionMask = 2147483647;
files = (
C8C56E162EE064CB00737D0E /* SharedImagePlugin.swift in Sources */,
C8C56E182EE0700A00737D0E /* AppBridgeViewController.swift in Sources */,
504EC3081FED79650016851F /* AppDelegate.swift in Sources */,
C8C56E142EE0474B00737D0E /* SharedImageUtility.swift in Sources */,
);
@@ -524,7 +517,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 68;
CURRENT_PROJECT_VERSION = 69;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_APP_SANDBOX = NO;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -535,7 +528,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -553,7 +546,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 68;
CURRENT_PROJECT_VERSION = 69;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_APP_SANDBOX = NO;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -564,7 +557,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
@@ -582,7 +575,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = TimeSafariShareExtension/TimeSafariShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 68;
CURRENT_PROJECT_VERSION = 69;
DEVELOPMENT_TEAM = GM3FS5JQPH;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
@@ -596,7 +589,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari.TimeSafariShareExtension;
@@ -620,7 +613,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = TimeSafariShareExtension/TimeSafariShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 68;
CURRENT_PROJECT_VERSION = 69;
DEVELOPMENT_TEAM = GM3FS5JQPH;
GCC_C_LANGUAGE_STANDARD = gnu17;
GENERATE_INFOPLIST_FILE = YES;
@@ -634,7 +627,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari.TimeSafariShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -0,0 +1,30 @@
//
// AppBridgeViewController.swift
// App
//
// Capacitor bridge view controller subclass.
//
// Phase 2B-1: registers the app-local SharedImagePlugin from the deterministic
// capacitorDidLoad() lifecycle callback, where the Capacitor bridge is
// guaranteed to exist. The existing AppDelegate registration is intentionally
// left in place as a temporary safety net during this phase.
//
import UIKit
import Capacitor
class AppBridgeViewController: CAPBridgeViewController {
override func capacitorDidLoad() {
super.capacitorDidLoad()
// Register the app-local SharedImage plugin using the same approach as
// AppDelegate. The @objc(SharedImage) annotation exposes it as
// "SharedImage" to JavaScript. At this point the bridge is guaranteed
// to be available (capacitorDidLoad runs immediately after the bridge
// is created).
let pluginInstance = SharedImagePlugin()
bridge?.registerPluginInstance(pluginInstance)
print("[AppBridgeViewController] ✅ Registered SharedImagePlugin (exposed as 'SharedImage' via @objc annotation)")
}
}

View File

@@ -9,72 +9,58 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// TEMPORARY SHARE TARGET DIAGNOSTICS
let launchURL = launchOptions?[.url] as? URL
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"didFinishLaunchingWithOptions urlSupplied=\(launchURL != nil) url=\(launchURL?.absoluteString ?? "nil") matchesTimesafari=\(AppDelegate.isTimesafariURL(launchURL)) launchOptionsHasURL=\(launchURL != nil) sharedImageActivationInvoked=false"
)
// Set notification center delegate so notifications show in foreground and rollover is triggered
UNUserNotificationCenter.current().delegate = self
// Initialize SQLite
//let sqlite = SQLite()
//sqlite.initialize()
// Register SharedImage plugin manually after bridge is ready
// Try multiple times with increasing delays to ensure bridge is initialized
var attempts = 0
let maxAttempts = 5
func tryRegister() {
attempts += 1
if registerSharedImagePlugin() {
print("[AppDelegate] ✅ Plugin registration successful on attempt \(attempts)")
} else if attempts < maxAttempts {
DispatchQueue.main.asyncAfter(deadline: .now() + Double(attempts) * 0.5) {
tryRegister()
}
} else {
print("[AppDelegate] ⚠️ Failed to register plugin after \(maxAttempts) attempts")
}
}
// Start registration attempts
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
tryRegister()
}
// SharedImagePlugin is registered from AppBridgeViewController.capacitorDidLoad()
// (Phase 2B-2). The previous AppDelegate retry-based registration was removed.
// Override point for customization after application launch.
return true
}
@discardableResult
private func registerSharedImagePlugin() -> Bool {
guard let window = self.window,
let bridgeVC = window.rootViewController as? CAPBridgeViewController,
let bridge = bridgeVC.bridge else {
return false
}
// Create plugin instance
// The @objc(SharedImage) annotation makes it available as "SharedImage" to Objective-C
// which matches the JavaScript registration name
let pluginInstance = SharedImagePlugin()
bridge.registerPluginInstance(pluginInstance)
print("[AppDelegate] ✅ Registered SharedImagePlugin (exposed as 'SharedImage' via @objc annotation)")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"applicationWillResignActive urlSupplied=false url=nil matchesTimesafari=false launchOptionsHasURL=false sharedImageActivationInvoked=false"
)
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"applicationDidEnterBackground urlSupplied=false url=nil matchesTimesafari=false launchOptionsHasURL=false sharedImageActivationInvoked=false"
)
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"applicationWillEnterForeground urlSupplied=false url=nil matchesTimesafari=false launchOptionsHasURL=false sharedImageActivationInvoked=false"
)
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"applicationDidBecomeActive urlSupplied=false url=nil matchesTimesafari=false launchOptionsHasURL=false sharedImageActivationInvoked=true"
)
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// Re-set notification delegate when app becomes active (in case Capacitor resets it)
@@ -116,7 +102,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
*/
private func checkForSharedImageOnActivation() {
// Check if shared photo is ready
if SharedImageUtility.isSharedPhotoReady() {
// TEMPORARY SHARE TARGET DIAGNOSTICS
let isReady = SharedImageUtility.isSharedPhotoReady()
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"checkForSharedImageOnActivation urlSupplied=false url=nil matchesTimesafari=false launchOptionsHasURL=false sharedImageActivationInvoked=true sharedPhotoReady=\(isReady)"
)
if isReady {
// Clear the flag
SharedImageUtility.clearSharedPhotoReadyFlag()
@@ -127,10 +119,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
func applicationWillTerminate(_ application: UIApplication) {
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"applicationWillTerminate urlSupplied=false url=nil matchesTimesafari=false launchOptionsHasURL=false sharedImageActivationInvoked=false"
)
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// TEMPORARY SHARE TARGET DIAGNOSTICS
SharedImageUtility.appendAppLaunchTrace(
"application(open:) urlSupplied=true url=\(url.absoluteString) matchesTimesafari=\(AppDelegate.isTimesafariURL(url)) launchOptionsHasURL=false sharedImageActivationInvoked=false"
)
// Called when the app was launched with a url. Feel free to add additional processing here,
// but if you want the App API to support tracking app url opens, make sure to keep this call
// Note: Share Extension opens app with timesafari:// (empty path), which is handled by JavaScript
@@ -138,6 +138,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/// Returns true when the supplied URL uses the timesafari:// scheme.
/// Diagnostics-only helper; does not affect URL handling.
private static func isTimesafariURL(_ url: URL?) -> Bool {
return url?.scheme?.lowercased() == "timesafari"
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// Called when the app was launched with an activity, including Universal Links.
// Feel free to add additional processing here, but if you want the App API to support

View File

@@ -11,7 +11,7 @@
<!--Bridge View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="CAPBridgeViewController" customModule="Capacitor" sceneMemberID="viewController"/>
<viewController id="BYZ-38-t0r" customClass="AppBridgeViewController" customModule="App" customModuleProvider="target" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>

View File

@@ -2,6 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>org.timesafari.dailynotification.fetch</string>
<string>org.timesafari.dailynotification.notify</string>
<string>org.timesafari.dailynotification.content-fetch</string>
<string>org.timesafari.dailynotification.notification-delivery</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
@@ -18,6 +25,17 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>app.timesafari</string>
<key>CFBundleURLSchemes</key>
<array>
<string>timesafari</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
@@ -26,6 +44,13 @@
<string>Time Safari allows you to take photos, and also scan QR codes from contacts.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Time Safari allows you to upload photos.</string>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
@@ -47,30 +72,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>app.timesafari</string>
<key>CFBundleURLSchemes</key>
<array>
<string>timesafari</string>
</array>
</dict>
</array>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>org.timesafari.dailynotification.fetch</string>
<string>org.timesafari.dailynotification.notify</string>
<string>org.timesafari.dailynotification.content-fetch</string>
<string>org.timesafari.dailynotification.notification-delivery</string>
</array>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
</dict>
</plist>

View File

@@ -24,7 +24,16 @@ public class SharedImagePlugin: CAPPlugin, CAPBridgedPlugin {
public var pluginMethods: [CAPPluginMethod] {
return [
CAPPluginMethod(#selector(getSharedImage(_:)), returnType: .promise),
CAPPluginMethod(#selector(hasSharedImage(_:)), returnType: .promise)
CAPPluginMethod(#selector(hasSharedImage(_:)), returnType: .promise),
CAPPluginMethod(#selector(getShareExtensionDiagnostics(_:)), returnType: .promise),
// TEMPORARY SHARE TARGET DIAGNOSTICS
CAPPluginMethod(#selector(getShareExtensionTrace(_:)), returnType: .promise),
// TEMPORARY SHARE TARGET DIAGNOSTICS
CAPPluginMethod(#selector(clearShareExtensionTrace(_:)), returnType: .promise),
// TEMPORARY SHARE TARGET DIAGNOSTICS
CAPPluginMethod(#selector(getAppLaunchTrace(_:)), returnType: .promise),
// TEMPORARY SHARE TARGET DIAGNOSTICS
CAPPluginMethod(#selector(clearAppLaunchTrace(_:)), returnType: .promise)
]
}
@@ -33,7 +42,7 @@ public class SharedImagePlugin: CAPPlugin, CAPBridgedPlugin {
/**
* Get shared image data from App Group UserDefaults
* Returns base64 string and fileName, or null if no image exists
* Clears the data after reading to prevent re-reading
* Read-only: native metadata and file are left intact after retrieval (Phase 1C)
*/
@objc public func getSharedImage(_ call: CAPPluginCall) {
guard let sharedData = SharedImageUtility.getSharedImageData() else {
@@ -62,5 +71,50 @@ public class SharedImagePlugin: CAPPlugin, CAPBridgedPlugin {
"hasImage": hasImage
])
}
/**
* Diagnostic snapshot of Share Extension startup and pending share state
*/
@objc public func getShareExtensionDiagnostics(_ call: CAPPluginCall) {
call.resolve(SharedImageUtility.getShareExtensionDiagnostics())
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Return the raw Share Extension execution trace log from the App Group container
*/
@objc public func getShareExtensionTrace(_ call: CAPPluginCall) {
call.resolve([
"trace": SharedImageUtility.getShareExtensionTrace()
])
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Delete the Share Extension execution trace log if present
*/
@objc public func clearShareExtensionTrace(_ call: CAPPluginCall) {
SharedImageUtility.clearShareExtensionTrace()
call.resolve()
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Return the raw app launch lifecycle trace log from the App Group container
*/
@objc public func getAppLaunchTrace(_ call: CAPPluginCall) {
call.resolve([
"trace": SharedImageUtility.getAppLaunchTrace()
])
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Delete the app launch lifecycle trace log if present
*/
@objc public func clearAppLaunchTrace(_ call: CAPPluginCall) {
SharedImageUtility.clearAppLaunchTrace()
call.resolve()
}
}

View File

@@ -13,22 +13,48 @@ public class SharedImageUtility {
private static let appGroupIdentifier = "group.app.timesafari.share"
private static let sharedPhotoFileNameKey = "sharedPhotoFileName"
private static let sharedPhotoFilePathKey = "sharedPhotoFilePath"
private static let sharedPhotoShareIdKey = "sharedPhotoShareId"
private static let shareExtensionLastStartKey = "shareExtensionLastStart"
private static let sharedPhotoReadyKey = "sharedPhotoReady"
// TEMPORARY SHARE TARGET DIAGNOSTICS
private static let shareExtensionTraceFileName = "share-extension-trace.log"
// TEMPORARY SHARE TARGET DIAGNOSTICS
private static let appLaunchTraceFileName = "app-launch-trace.log"
/// Get the App Group container URL for accessing shared files
private static var appGroupContainerURL: URL? {
return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)
}
private static func logShareDiagnostic(method: String, userDefaults: UserDefaults?) {
let shareId = userDefaults?.string(forKey: sharedPhotoShareIdKey)
let filePath = userDefaults?.string(forKey: sharedPhotoFilePathKey)
let metadataExists = filePath != nil
let fileExists: Bool
if let filePath = filePath, let containerURL = appGroupContainerURL {
let fileURL = containerURL.appendingPathComponent(filePath)
fileExists = FileManager.default.fileExists(atPath: fileURL.path)
} else {
fileExists = false
}
let shareIdLog = shareId ?? "nil"
let filePathLog = filePath ?? "nil"
print("[ShareTarget] \(method) shareId=\(shareIdLog) sharedPhotoFilePath=\(filePathLog) metadataExists=\(metadataExists) fileExists=\(fileExists)")
}
/**
* Get shared image data from App Group container file
* All images are stored as files for consistency and to avoid UserDefaults size limits
* Clears the data after reading to prevent re-reading
* Read-only: metadata and file are left intact after retrieval (Phase 1C)
*
* @returns Dictionary with "base64" and "fileName" keys, or nil if no shared image
*/
static func getSharedImageData() -> [String: String]? {
guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier) else {
let userDefaults = UserDefaults(suiteName: appGroupIdentifier)
logShareDiagnostic(method: "getSharedImageData", userDefaults: userDefaults)
guard let userDefaults = userDefaults else {
return nil
}
@@ -39,25 +65,21 @@ public class SharedImageUtility {
}
let fileName = userDefaults.string(forKey: sharedPhotoFileNameKey) ?? "shared-image.jpg"
let shareId = userDefaults.string(forKey: sharedPhotoShareIdKey)
let fileURL = containerURL.appendingPathComponent(filePath)
// Read image data from file
guard let imageData = try? Data(contentsOf: fileURL) else {
return nil
}
let resolvedShareId = shareId ?? "unknown"
print("[ShareTarget] shareId=\(resolvedShareId) retrieved")
print("[ShareTarget] shareId=\(resolvedShareId) left intact after retrieval")
// Convert file data to base64 for JavaScript consumption
let base64String = imageData.base64EncodedString()
// Clear the shared data after reading
userDefaults.removeObject(forKey: sharedPhotoFilePathKey)
userDefaults.removeObject(forKey: sharedPhotoFileNameKey)
// Remove the file
try? FileManager.default.removeItem(at: fileURL)
userDefaults.synchronize()
return ["base64": base64String, "fileName": fileName]
}
@@ -67,7 +89,10 @@ public class SharedImageUtility {
* @returns true if shared image file exists, false otherwise
*/
static func hasSharedImage() -> Bool {
guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier),
let userDefaults = UserDefaults(suiteName: appGroupIdentifier)
logShareDiagnostic(method: "hasSharedImage", userDefaults: userDefaults)
guard let userDefaults = userDefaults,
let filePath = userDefaults.string(forKey: sharedPhotoFilePathKey),
let containerURL = appGroupContainerURL else {
return false
@@ -76,7 +101,129 @@ public class SharedImageUtility {
let fileURL = containerURL.appendingPathComponent(filePath)
return FileManager.default.fileExists(atPath: fileURL.path)
}
/**
* Diagnostic snapshot of Share Extension startup and pending share state
* Read-only: does not modify App Group storage
*/
static func getShareExtensionDiagnostics() -> [String: Any] {
guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier) else {
return [
"shareExtensionLastStart": NSNull(),
"sharedPhotoShareId": NSNull(),
"sharedPhotoFilePath": NSNull(),
"fileExists": false,
// TEMPORARY SHARE TARGET DIAGNOSTICS
"pendingShareExists": false
]
}
let shareExtensionLastStart = userDefaults.string(forKey: shareExtensionLastStartKey)
let shareId = userDefaults.string(forKey: sharedPhotoShareIdKey)
let filePath = userDefaults.string(forKey: sharedPhotoFilePathKey)
let fileExists: Bool
if let filePath = filePath, let containerURL = appGroupContainerURL {
let fileURL = containerURL.appendingPathComponent(filePath)
fileExists = FileManager.default.fileExists(atPath: fileURL.path)
} else {
fileExists = false
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
let pendingShareExists = (
shareExtensionLastStart != nil ||
shareId != nil ||
filePath != nil ||
fileExists == true
)
print("[ShareTarget] getShareExtensionDiagnostics shareExtensionLastStart=\(shareExtensionLastStart ?? "nil") sharedPhotoShareId=\(shareId ?? "nil") sharedPhotoFilePath=\(filePath ?? "nil") fileExists=\(fileExists) pendingShareExists=\(pendingShareExists)")
return [
"shareExtensionLastStart": shareExtensionLastStart ?? NSNull(),
"sharedPhotoShareId": shareId ?? NSNull(),
"sharedPhotoFilePath": filePath ?? NSNull(),
"fileExists": fileExists,
// TEMPORARY SHARE TARGET DIAGNOSTICS
"pendingShareExists": pendingShareExists
]
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Read the Share Extension trace file from the App Group container.
* Read-only: does not modify or delete the trace file.
*
* @returns the full trace contents, or an empty string if no trace exists
*/
static func getShareExtensionTrace() -> String {
guard let containerURL = appGroupContainerURL else {
return ""
}
let fileURL = containerURL.appendingPathComponent(shareExtensionTraceFileName)
return (try? String(contentsOf: fileURL, encoding: .utf8)) ?? ""
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Delete the Share Extension trace file from the App Group container if present.
*/
static func clearShareExtensionTrace() {
guard let containerURL = appGroupContainerURL else {
return
}
let fileURL = containerURL.appendingPathComponent(shareExtensionTraceFileName)
try? FileManager.default.removeItem(at: fileURL)
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Append a single timestamped line to the app launch trace file in the
* App Group container. Each line is prefixed with an ISO8601 timestamp.
* Append-only; logging failures are intentionally swallowed (diagnostics only).
*/
static func appendAppLaunchTrace(_ message: String) {
guard let containerURL = appGroupContainerURL else { return }
let fileURL = containerURL.appendingPathComponent(appLaunchTraceFileName)
let timestamp = ISO8601DateFormatter().string(from: Date())
let line = "\(timestamp) \(message)\n"
guard let data = line.data(using: .utf8) else { return }
if let handle = try? FileHandle(forWritingTo: fileURL) {
defer { try? handle.close() }
_ = try? handle.seekToEnd()
try? handle.write(contentsOf: data)
} else {
try? data.write(to: fileURL, options: .atomic)
}
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Read the app launch trace file from the App Group container.
* Read-only: does not modify or delete the trace file.
*
* @returns the full trace contents, or an empty string if no trace exists
*/
static func getAppLaunchTrace() -> String {
guard let containerURL = appGroupContainerURL else {
return ""
}
let fileURL = containerURL.appendingPathComponent(appLaunchTraceFileName)
return (try? String(contentsOf: fileURL, encoding: .utf8)) ?? ""
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Delete the app launch trace file from the App Group container if present.
*/
static func clearAppLaunchTrace() {
guard let containerURL = appGroupContainerURL else {
return
}
let fileURL = containerURL.appendingPathComponent(appLaunchTraceFileName)
try? FileManager.default.removeItem(at: fileURL)
}
/**
* Check if shared photo ready flag is set
* This flag is set by the Share Extension when image is ready

View File

@@ -76,7 +76,7 @@ PODS:
- SQLCipher/common (4.10.0)
- SQLCipher/standard (4.10.0):
- SQLCipher/common
- TimesafariDailyNotificationPlugin (2.0.0):
- TimesafariDailyNotificationPlugin (4.0.1):
- Capacitor
- ZIPFoundation (0.9.20)
@@ -162,7 +162,7 @@ SPEC CHECKSUMS:
nanopb: fad817b59e0457d11a5dfbde799381cd727c1275
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
SQLCipher: eb79c64049cb002b4e9fcb30edb7979bf4706dfc
TimesafariDailyNotificationPlugin: 3c12e8c39fc27f689f56cf4e57230a8c28611fcc
TimesafariDailyNotificationPlugin: 69277c884380a9a620f671b68e0327eaa4b3d27d
ZIPFoundation: dfd3d681c4053ff7e2f7350bc4e53b5dba3f5351
PODFILE CHECKSUM: 87c07d03f36ef38ab0c873802aee1ce9b5d34448

View File

@@ -9,135 +9,264 @@ import UIKit
import UniformTypeIdentifiers
class ShareViewController: UIViewController {
private let appGroupIdentifier = "group.app.timesafari.share"
private let sharedPhotoFileNameKey = "sharedPhotoFileName"
private let sharedPhotoFilePathKey = "sharedPhotoFilePath"
private let sharedPhotoShareIdKey = "sharedPhotoShareId"
private let shareExtensionLastStartKey = "shareExtensionLastStart"
private let sharedImageFileName = "shared-image"
// TEMPORARY SHARE TARGET DIAGNOSTICS
private let shareExtensionTraceFileName = "share-extension-trace.log"
/// Get the App Group container URL for storing shared files
private var appGroupContainerURL: URL? {
return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/// Append a single timestamped line to the Share Extension trace file in the
/// App Group container. Each line is prefixed with an ISO8601 timestamp.
/// Logging failures are intentionally ignored (diagnostics only).
private func appendTrace(_ message: String) {
guard let containerURL = appGroupContainerURL else { return }
let fileURL = containerURL.appendingPathComponent(shareExtensionTraceFileName)
let timestamp = ISO8601DateFormatter().string(from: Date())
let line = "\(timestamp) \(message)\n"
guard let data = line.data(using: .utf8) else { return }
if let handle = try? FileHandle(forWritingTo: fileURL) {
defer { try? handle.close() }
_ = try? handle.seekToEnd()
try? handle.write(contentsOf: data)
} else {
try? data.write(to: fileURL, options: .atomic)
}
}
override func viewDidLoad() {
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("viewDidLoad START")
if let userDefaults = UserDefaults(suiteName: appGroupIdentifier) {
let timestamp = ISO8601DateFormatter().string(from: Date())
userDefaults.set(timestamp, forKey: shareExtensionLastStartKey)
userDefaults.synchronize()
print("[ShareTarget] shareExtensionLastStart=\(timestamp)")
}
print("[ShareTarget] viewDidLoad started")
super.viewDidLoad()
// Set a minimal background (transparent or loading indicator)
view.backgroundColor = .systemBackground
// Process image immediately without showing UI
processAndOpenApp()
print("[ShareTarget] viewDidLoad completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("viewDidLoad END")
}
private func processAndOpenApp() {
print("[ShareTarget] processAndOpenApp started")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("processAndOpenApp START")
// extensionContext is automatically available on UIViewController when used as extension principal class
guard let context = extensionContext,
let inputItems = context.inputItems as? [NSExtensionItem] else {
print("[ShareTarget] processAndOpenApp failed: missing extensionContext or inputItems")
print("[ShareTarget] completeRequest starting")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("completeRequest START")
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
print("[ShareTarget] completeRequest completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("completeRequest END")
print("[ShareTarget] processAndOpenApp completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("processAndOpenApp END")
return
}
let attachmentCount = inputItems.reduce(0) { count, item in
count + (item.attachments?.count ?? 0)
}
print("[ShareTarget] processAndOpenApp inputItems=\(inputItems.count) attachmentCount=\(attachmentCount)")
processSharedImage(from: inputItems) { [weak self] success in
guard let self = self, let context = self.extensionContext else {
print("[ShareTarget] processAndOpenApp failed: self or extensionContext unavailable in completion")
print("[ShareTarget] processAndOpenApp completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self?.appendTrace("processAndOpenApp END")
return
}
if success {
// Set flag that shared photo is ready
self.setSharedPhotoReadyFlag()
// Open the main app (using minimal URL - app will detect shared data on activation)
self.openMainApp()
} else {
print("[ShareTarget] processAndOpenApp failed: processSharedImage returned false")
}
// Complete immediately - no UI shown
print("[ShareTarget] completeRequest starting")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("completeRequest START")
context.completeRequest(returningItems: [], completionHandler: nil)
print("[ShareTarget] completeRequest completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("completeRequest END")
print("[ShareTarget] processAndOpenApp completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("processAndOpenApp END")
}
}
private func setSharedPhotoReadyFlag() {
print("[ShareTarget] setSharedPhotoReadyFlag started")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("setSharedPhotoReadyFlag START")
guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier) else {
print("[ShareTarget] setSharedPhotoReadyFlag failed: UserDefaults unavailable for app group")
print("[ShareTarget] setSharedPhotoReadyFlag completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("setSharedPhotoReadyFlag FAILURE")
return
}
userDefaults.set(true, forKey: "sharedPhotoReady")
userDefaults.synchronize()
print("[ShareTarget] setSharedPhotoReadyFlag success")
print("[ShareTarget] setSharedPhotoReadyFlag completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("setSharedPhotoReadyFlag SUCCESS")
}
private func processSharedImage(from items: [NSExtensionItem], completion: @escaping (Bool) -> Void) {
let attachmentCount = items.reduce(0) { count, item in
count + (item.attachments?.count ?? 0)
}
print("[ShareTarget] processSharedImage started attachmentCount=\(attachmentCount)")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("processSharedImage START")
// Find the first image attachment
for item in items {
guard let attachments = item.attachments else {
print("[ShareTarget] processSharedImage skipping item with no attachments")
continue
}
for attachment in attachments {
// Skip non-image attachments
guard attachment.hasItemConformingToTypeIdentifier(UTType.image.identifier) else {
print("[ShareTarget] processSharedImage skipping non-image attachment")
continue
}
let shareId = UUID().uuidString
print("[ShareTarget] processSharedImage found image attachment shareId=\(shareId) UTType=\(UTType.image.identifier)")
print("[ShareTarget] share received shareId=\(shareId)")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("image attachment found shareId=\(shareId)")
// Try to load raw data first to preserve original format
// This preserves the original image format without conversion
attachment.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil) { [weak self] (data, error) in
guard let self = self else {
completion(false)
return
}
if error != nil {
completion(false)
return
}
// Handle different image data types
// loadItem(forTypeIdentifier:) typically returns URL or Data, not UIImage
var imageData: Data?
var fileName: String = "shared-image"
if let url = data as? URL {
// Most common case: Image provided as file URL - read raw data to preserve format
let accessing = url.startAccessingSecurityScopedResource()
defer {
if accessing {
url.stopAccessingSecurityScopedResource()
}
}
// Read raw data directly to preserve original format
imageData = try? Data(contentsOf: url)
fileName = url.lastPathComponent
// Fallback: if raw data read fails, try UIImage and convert to PNG (lossless)
if imageData == nil, let image = UIImage(contentsOfFile: url.path) {
imageData = image.pngData()
fileName = self.getFileNameWithExtension(url.lastPathComponent, newExtension: "png")
}
} else if let data = data as? Data {
// Less common: Image provided as raw Data - use directly to preserve format
imageData = data
fileName = attachment.suggestedName ?? "shared-image"
}
guard let finalImageData = imageData else {
completion(false)
return
}
// Store image as file in App Group container
if self.storeImageData(finalImageData, fileName: fileName) {
completion(true)
} else {
completion(false)
}
guard let self = self else {
print("[ShareTarget] processSharedImage failed: self unavailable in loadItem callback shareId=\(shareId)")
print("[ShareTarget] processSharedImage completed shareId=\(shareId) success=false")
completion(false)
return
}
return // Process only the first image
if let error = error {
print("[ShareTarget] processSharedImage failed: loadItem error shareId=\(shareId) error=\(error.localizedDescription)")
print("[ShareTarget] processSharedImage completed shareId=\(shareId) success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("processSharedImage END success=false")
completion(false)
return
}
// Handle different image data types
// loadItem(forTypeIdentifier:) typically returns URL or Data, not UIImage
var imageData: Data?
var fileName: String = "shared-image"
if let url = data as? URL {
print("[ShareTarget] processSharedImage loadItem returned URL shareId=\(shareId) url=\(url.lastPathComponent)")
// Most common case: Image provided as file URL - read raw data to preserve format
let accessing = url.startAccessingSecurityScopedResource()
defer {
if accessing {
url.stopAccessingSecurityScopedResource()
}
}
// Read raw data directly to preserve original format
imageData = try? Data(contentsOf: url)
fileName = url.lastPathComponent
// Fallback: if raw data read fails, try UIImage and convert to PNG (lossless)
if imageData == nil, let image = UIImage(contentsOfFile: url.path) {
print("[ShareTarget] processSharedImage using UIImage PNG fallback shareId=\(shareId)")
imageData = image.pngData()
fileName = self.getFileNameWithExtension(url.lastPathComponent, newExtension: "png")
} else if imageData == nil {
print("[ShareTarget] processSharedImage failed: could not read image data from URL shareId=\(shareId)")
}
} else if let data = data as? Data {
print("[ShareTarget] processSharedImage loadItem returned Data shareId=\(shareId)")
// Less common: Image provided as raw Data - use directly to preserve format
imageData = data
fileName = attachment.suggestedName ?? "shared-image"
} else {
print("[ShareTarget] processSharedImage failed: loadItem returned unexpected type shareId=\(shareId) type=\(String(describing: type(of: data)))")
}
guard let finalImageData = imageData else {
print("[ShareTarget] processSharedImage failed: no image data shareId=\(shareId)")
print("[ShareTarget] processSharedImage completed shareId=\(shareId) success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("processSharedImage END success=false")
completion(false)
return
}
print("[ShareTarget] image loaded bytes=\(finalImageData.count) filename=\(fileName) shareId=\(shareId)")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("image loaded shareId=\(shareId) bytes=\(finalImageData.count)")
// Store image as file in App Group container
if self.storeImageData(finalImageData, fileName: fileName, shareId: shareId) {
print("[ShareTarget] processSharedImage completed shareId=\(shareId) success=true")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("processSharedImage END success=true")
completion(true)
} else {
print("[ShareTarget] processSharedImage failed: storeImageData returned false shareId=\(shareId)")
print("[ShareTarget] processSharedImage completed shareId=\(shareId) success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
self.appendTrace("processSharedImage END success=false")
completion(false)
}
}
return // Process only the first image
}
}
// No image found
print("[ShareTarget] processSharedImage failed: no image attachment found attachmentCount=\(attachmentCount)")
print("[ShareTarget] processSharedImage completed success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("processSharedImage END success=false")
completion(false)
}
/// Helper to get filename with a new extension, preserving base name
private func getFileNameWithExtension(_ originalName: String, newExtension: String) -> String {
if let nameWithoutExt = originalName.components(separatedBy: ".").first, !nameWithoutExt.isEmpty {
@@ -145,63 +274,116 @@ class ShareViewController: UIViewController {
}
return "shared-image.\(newExtension)"
}
/// Extract file extension from original filename, defaulting to jpg when absent
private func fileExtension(from fileName: String) -> String {
let ext = (fileName as NSString).pathExtension
return ext.isEmpty ? "jpg" : ext.lowercased()
}
/// Build unique on-disk filename: <shareId>.<extension>
private func storedFileName(shareId: String, originalFileName: String) -> String {
return "\(shareId).\(fileExtension(from: originalFileName))"
}
/// Store image data as a file in the App Group container
/// All images are stored as files regardless of size for consistency and simplicity
/// Returns true if successful, false otherwise
private func storeImageData(_ imageData: Data, fileName: String) -> Bool {
private func storeImageData(_ imageData: Data, fileName: String, shareId: String) -> Bool {
print("[ShareTarget] storeImageData started shareId=\(shareId) bytes=\(imageData.count) filename=\(fileName)")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("storeImageData START shareId=\(shareId)")
guard let containerURL = appGroupContainerURL else {
print("[ShareTarget] storeImageData failed: app group container unavailable shareId=\(shareId)")
print("[ShareTarget] storeImageData completed shareId=\(shareId) success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("storeImageData FAILURE shareId=\(shareId)")
return false
}
// Create file URL in the container using the actual filename
// Extract extension from fileName if present, otherwise use sharedImageFileName
let actualFileName = fileName.isEmpty ? sharedImageFileName : fileName
let fileURL = containerURL.appendingPathComponent(actualFileName)
// Remove old file if it exists
try? FileManager.default.removeItem(at: fileURL)
let originalFileName = fileName.isEmpty ? "\(sharedImageFileName).jpg" : fileName
let storedFileName = storedFileName(shareId: shareId, originalFileName: originalFileName)
let fileURL = containerURL.appendingPathComponent(storedFileName)
// Remove previously pending share file (metadata tracks one share at a time)
if let userDefaults = UserDefaults(suiteName: appGroupIdentifier),
let previousPath = userDefaults.string(forKey: sharedPhotoFilePathKey) {
let previousURL = containerURL.appendingPathComponent(previousPath)
if previousURL != fileURL {
try? FileManager.default.removeItem(at: previousURL)
}
}
// Write image data to file
do {
try imageData.write(to: fileURL)
} catch {
print("[ShareTarget] storeImageData failed: file write error shareId=\(shareId) error=\(error.localizedDescription)")
print("[ShareTarget] storeImageData completed shareId=\(shareId) success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("storeImageData FAILURE shareId=\(shareId)")
return false
}
print("[ShareTarget] file stored shareId=\(shareId) originalFilename=\(originalFileName) storedFilename=\(storedFileName)")
// Store file path and filename in UserDefaults (small data, safe to store)
guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier) else {
print("[ShareTarget] storeImageData failed: UserDefaults unavailable shareId=\(shareId)")
print("[ShareTarget] storeImageData completed shareId=\(shareId) success=false")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("storeImageData FAILURE shareId=\(shareId)")
return false
}
// Store relative path and filename
userDefaults.set(actualFileName, forKey: sharedPhotoFilePathKey)
userDefaults.set(fileName, forKey: sharedPhotoFileNameKey)
// sharedPhotoFilePath = on-disk name; sharedPhotoFileName = original display name
userDefaults.set(storedFileName, forKey: sharedPhotoFilePathKey)
userDefaults.set(originalFileName, forKey: sharedPhotoFileNameKey)
userDefaults.set(shareId, forKey: sharedPhotoShareIdKey)
// Clean up any old base64 data that might exist
userDefaults.removeObject(forKey: "sharedPhotoBase64")
userDefaults.synchronize()
print("[ShareTarget] metadata stored shareId=\(shareId) originalFilename=\(originalFileName) storedFilename=\(storedFileName)")
print("[ShareTarget] storeImageData success shareId=\(shareId)")
print("[ShareTarget] storeImageData completed shareId=\(shareId) success=true")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("storeImageData SUCCESS shareId=\(shareId)")
return true
}
private func openMainApp() {
print("[ShareTarget] openMainApp starting")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("openMainApp START")
// Open the main app with minimal URL - app will detect shared data on activation
guard let url = URL(string: "timesafari://") else {
print("[ShareTarget] openMainApp failed: could not create timesafari:// URL")
print("[ShareTarget] openMainApp completed")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("openMainApp FAILURE")
return
}
var responder: UIResponder? = self
while responder != nil {
if let application = responder as? UIApplication {
application.open(url, options: [:], completionHandler: nil)
print("[ShareTarget] openMainApp completed via UIApplication")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("openMainApp SUCCESS")
return
}
responder = responder?.next
}
// Fallback: use extension context
extensionContext?.open(url, completionHandler: nil)
print("[ShareTarget] openMainApp completed via extensionContext fallback")
// TEMPORARY SHARE TARGET DIAGNOSTICS
appendTrace("openMainApp SUCCESS")
}
}

1611
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
{
"name": "giftopia",
"version": "1.4.2",
"version": "1.4.3",
"description": "Giftopia App",
"author": {
"name": "Gift Economies Team"
@@ -14,6 +14,7 @@
"prebuild": "eslint --ext .js,.ts,.vue --ignore-path .gitignore src && node sw_combine.js && node scripts/copy-wasm.js",
"test:prerequisites": "node scripts/check-prerequisites.js",
"check:dependencies": "./scripts/check-dependencies.sh",
"deps:update-daily-notification-plugin": "npm install @timesafari/daily-notification-plugin@git+https://gitea.anomalistdesign.com/trent_larson/daily-notification-plugin.git#master",
"test:all": "npm run lint && tsc && npm run test:web && npm run test:mobile && ./scripts/test-safety-check.sh && echo '\n\n\nGotta add the performance tests'",
"test:web": "npx playwright test -c playwright.config-local.ts --trace on",
"test:mobile": "./scripts/test-mobile.sh",

View File

@@ -8,14 +8,14 @@ notifications for conflicted entities * - Template streamlined with computed CSS
properties * * @author Matthew Raymer */
<template>
<div id="sectionGiftedGiver">
<label class="block font-bold mb-1">
<label class="block font-semibold text-lg capitalize text-center">
{{ stepLabel }}
</label>
<!-- Toggle link for entity type selection -->
<div class="text-right mb-4">
<div class="text-center mb-4">
<button
type="button"
class="text-sm text-blue-600 hover:text-blue-800 underline font-medium"
class="text-xs text-blue-600 hover:underline uppercase"
@click="handleToggleEntityType"
>
{{ toggleLinkText }}

View File

@@ -359,6 +359,75 @@ async function checkForSharedImageAndNavigate() {
}
try {
// TEMPORARY SHARE TARGET DIAGNOSTICS
if (Capacitor.getPlatform() === "ios") {
try {
const diagnostics = await SharedImage.getShareExtensionDiagnostics();
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info(
"[ShareTarget] Cold-start state",
JSON.stringify({
pendingShareExists: diagnostics.pendingShareExists,
shareExtensionLastStart: diagnostics.shareExtensionLastStart,
sharedPhotoShareId: diagnostics.sharedPhotoShareId,
sharedPhotoFilePath: diagnostics.sharedPhotoFilePath,
fileExists: diagnostics.fileExists,
currentRoute: router.currentRoute.value.fullPath,
appReady: true,
timestamp: new Date().toISOString(),
}),
);
logger.info(`[ShareTarget] Diagnostics ${JSON.stringify(diagnostics)}`);
} catch (diagnosticsError) {
logger.info(
`[ShareTarget] Diagnostics ${JSON.stringify({
error:
diagnosticsError instanceof Error
? diagnosticsError.message
: String(diagnosticsError),
})}`,
);
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
const traceResult = await SharedImage.getShareExtensionTrace();
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info("[ShareTarget] TRACE FULL START");
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info(traceResult.trace);
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info("[ShareTarget] TRACE FULL END");
// TEMPORARY SHARE TARGET DIAGNOSTICS
if (Capacitor.getPlatform() === "ios") {
alert(traceResult.trace);
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info("[ShareTarget] Extension Trace\n" + traceResult.trace);
// TEMPORARY SHARE TARGET DIAGNOSTICS
const traceLength = traceResult.trace.length;
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info(`[ShareTarget] TRACE LENGTH=${traceLength}`);
// TEMPORARY SHARE TARGET DIAGNOSTICS
if (traceLength > 0) {
console.info(
"[ShareTarget] TRACE FIRST 500\n" + traceResult.trace.slice(0, 500),
);
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
const launchTraceResult = await SharedImage.getAppLaunchTrace();
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info("[ShareTarget] APP LAUNCH TRACE START");
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info(launchTraceResult.trace);
// TEMPORARY SHARE TARGET DIAGNOSTICS
console.info("[ShareTarget] APP LAUNCH TRACE END");
}
logger.debug("[Main] 🔍 Checking for shared image on app activation");
const imageResult = await checkAndStoreNativeSharedImage();
@@ -405,22 +474,22 @@ logger.info(`[Main] ✅ App mounted successfully`);
// Check for shared image on initial load (in case app was launched from share sheet)
// On Android, share intents are processed in MainActivity.onCreate, so we need to check
// after a delay to ensure the native code has finished processing
if (
Capacitor.isNativePlatform() &&
(Capacitor.getPlatform() === "ios" || Capacitor.getPlatform() === "android")
) {
// Use multiple checks with increasing delays to handle timing issues
// Android share intent processing happens in onCreate, which may complete after JS loads
const checkDelays =
Capacitor.getPlatform() === "android"
? [500, 1500, 3000] // Android needs more time for share intent processing
: [1000]; // iOS is faster
if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === "android") {
// Android behavior unchanged: multiple checks with increasing delays because
// share intent processing happens in onCreate, which may complete after JS loads.
const checkDelays = [500, 1500, 3000]; // Android needs more time for share intent processing
checkDelays.forEach((delay) => {
setTimeout(async () => {
await checkForSharedImageAndNavigate();
}, delay);
});
} else if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === "ios") {
// Phase 2B-3: the SharedImage plugin is now registered deterministically from
// AppBridgeViewController.capacitorDidLoad() before the web layer loads, so it
// is guaranteed to exist here. Perform the initial shared-image check
// immediately without waiting/polling for plugin readiness.
void checkForSharedImageAndNavigate();
}
// Listen for app state changes to detect when app becomes active

View File

@@ -4,7 +4,15 @@
*/
import { WebPlugin } from "@capacitor/core";
import type { SharedImagePlugin, SharedImageResult } from "./definitions";
import type {
SharedImagePlugin,
SharedImageResult,
ShareExtensionDiagnostics,
// TEMPORARY SHARE TARGET DIAGNOSTICS
ShareExtensionTrace,
// TEMPORARY SHARE TARGET DIAGNOSTICS
AppLaunchTrace,
} from "./definitions";
export class SharedImagePluginWeb
extends WebPlugin
@@ -18,4 +26,35 @@ export class SharedImagePluginWeb
async hasSharedImage(): Promise<{ hasImage: boolean }> {
return { hasImage: false };
}
async getShareExtensionDiagnostics(): Promise<ShareExtensionDiagnostics> {
return {
shareExtensionLastStart: null,
sharedPhotoShareId: null,
sharedPhotoFilePath: null,
fileExists: false,
// TEMPORARY SHARE TARGET DIAGNOSTICS
pendingShareExists: false,
};
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
async getShareExtensionTrace(): Promise<ShareExtensionTrace> {
return { trace: "" };
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
async clearShareExtensionTrace(): Promise<void> {
// Web platform doesn't support native sharing - no-op
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
async getAppLaunchTrace(): Promise<AppLaunchTrace> {
return { trace: "" };
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
async clearAppLaunchTrace(): Promise<void> {
// Web platform doesn't support native launch tracing - no-op
}
}

View File

@@ -7,11 +7,30 @@ export interface SharedImageResult {
fileName: string;
}
export interface ShareExtensionDiagnostics {
shareExtensionLastStart: string | null;
sharedPhotoShareId: string | null;
sharedPhotoFilePath: string | null;
fileExists: boolean;
// TEMPORARY SHARE TARGET DIAGNOSTICS
pendingShareExists: boolean;
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
export interface ShareExtensionTrace {
trace: string;
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
export interface AppLaunchTrace {
trace: string;
}
export interface SharedImagePlugin {
/**
* Get shared image data from native layer
* Returns base64 string and fileName, or null if no image exists
* Clears the data after reading to prevent re-reading
* Read-only on iOS: native metadata and file are left intact after retrieval (Phase 1C)
*/
getSharedImage(): Promise<SharedImageResult | null>;
@@ -20,4 +39,33 @@ export interface SharedImagePlugin {
* Useful for quick checks before calling getSharedImage()
*/
hasSharedImage(): Promise<{ hasImage: boolean }>;
/**
* Diagnostic snapshot of Share Extension startup and pending share state (iOS)
*/
getShareExtensionDiagnostics(): Promise<ShareExtensionDiagnostics>;
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Read the raw Share Extension execution trace log (iOS)
*/
getShareExtensionTrace(): Promise<ShareExtensionTrace>;
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Delete the Share Extension execution trace log if present (iOS)
*/
clearShareExtensionTrace(): Promise<void>;
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Read the raw app launch lifecycle trace log (iOS)
*/
getAppLaunchTrace(): Promise<AppLaunchTrace>;
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Delete the app launch lifecycle trace log if present (iOS)
*/
clearAppLaunchTrace(): Promise<void>;
}

View File

@@ -290,6 +290,12 @@ const routes: Array<RouteRecordRaw> = [
name: "test",
component: () => import("../views/TestView.vue"),
},
// TEMPORARY SHARE TARGET DIAGNOSTICS
{
path: "/share-target-debug",
name: "share-target-debug",
component: () => import("../views/ShareTargetDebugView.vue"),
},
{
path: "/user-profile/:id?",
name: "user-profile",

View File

@@ -62,10 +62,6 @@ export class NativeNotificationService implements NotificationServiceInterface {
return true;
}
/**
* Request notification permissions from the OS
* Shows native permission dialog on first call
*/
/**
* Request notification permissions from the OS
* Shows native permission dialog on first call

View File

@@ -1402,54 +1402,6 @@ export default class AccountViewView extends Vue {
}, 150);
}
/**
* Toggle dev-only 10-minute rollover for daily reminder. Saves the setting and,
* if reminder is already on, reschedules so the plugin uses the new interval.
*/
async toggleReminderFastRollover(): Promise<void> {
const next = !this.reminderFastRolloverForTesting;
await this.$saveSettings({
reminderFastRolloverForTesting: next,
});
this.reminderFastRolloverForTesting = next;
if (this.notifyingReminder) {
try {
const service = NotificationService.getInstance();
if (Capacitor.getPlatform() !== "android") {
await service.cancelDailyNotification();
}
const time24h = this.parseTimeTo24Hour(this.notifyingReminderTime);
const title = "Daily Reminder";
const body =
this.notifyingReminderMessage ||
"Click to share some gratitude with the world -- even if they're unnamed.";
await service.scheduleDailyNotification({
time: time24h,
title,
body,
priority: "normal",
...(next ? { rolloverIntervalMinutes: 10 } : {}),
});
this.notify.success(
next
? "Reminder will repeat every 10 minutes (testing)."
: "Reminder will repeat daily (24h).",
TIMEOUTS.STANDARD,
);
} catch (err) {
logger.error(
"[AccountViewView] Reschedule after fast-rollover toggle failed:",
err,
);
this.notify.error(
"Failed to update reminder interval. Please try again.",
TIMEOUTS.STANDARD,
);
}
}
}
/**
* Parse time string (e.g., "5:22 PM") to 24-hour format (e.g., "17:22")
*/

View File

@@ -1,4 +1,6 @@
<template>
<QuickNav />
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<TopMessage />

View File

@@ -109,12 +109,14 @@ Raymer * @version 1.0.0 */
<div v-if="isUserRegistered" id="sectionRecordSomethingGiven">
<!-- Record Quick-Action -->
<div class="mb-6">
<div class="flex gap-2 items-center mb-2">
<div
class="bg-slate-100 border border-slate-300 rounded-md px-4 py-2.5 mb-4"
>
<div class="flex gap-2 justify-between items-center ps-8">
<!-- Thank button - always visible and unchanged -->
<button
type="button"
class="text-center text-base uppercase bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white flex items-center justify-center gap-2 px-4 py-3 rounded-full"
class="text-center text-xl uppercase font-bold bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white flex items-center justify-center gap-2 mx-auto px-6 py-2 rounded-lg"
@click="openPersonDialog()"
>
<font-awesome icon="plus" />
@@ -122,25 +124,29 @@ Raymer * @version 1.0.0 */
</button>
<!-- Plus button - appears when scrolled, positioned over house-chimney icon -->
<transition
enter-active-class="transition-all duration-1000 ease-out"
leave-active-class="transition-all duration-1000 ease-in"
enter-from-class="scale-0"
enter-to-class="scale-100"
leave-from-class="scale-100"
leave-to-class="scale-0"
enter-active-class="transition-all duration-500 ease-out"
leave-active-class="transition-all duration-500 ease-in"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<button
<div
v-if="isScrolled"
type="button"
class="fixed bottom-10 p-4 w-14 h-14 z-50 text-center bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white rounded-full flex items-center justify-center"
:style="getButtonPosition()"
@click="openPersonDialog()"
class="bg-gradient-to-t from-white to-transparent fixed inset-x-0 bottom-[calc(4.75rem+max(env(safe-area-inset-bottom),var(--safe-area-inset-bottom,0px)))] px-4 pb-3 w-full z-[49]"
>
<font-awesome icon="plus" />
</button>
<button
type="button"
class="text-center text-xl uppercase font-bold bg-gradient-to-b from-green-400 to-green-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white flex items-center justify-center gap-2 mx-auto px-6 py-2 rounded-lg drop-shadow-[0_0_10px_rgba(255,255,255,1)]"
@click="openPersonDialog()"
>
<font-awesome icon="plus" />
<span>Thank</span>
</button>
</div>
</transition>
<button
class="block ms-auto text-sm text-center text-white bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] p-1.5 rounded-full"
class="block text-sm text-center text-white bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] p-1.5 rounded-full"
@click="openGiftedPrompts()"
>
<font-awesome
@@ -559,7 +565,7 @@ export default class HomeView extends Vue {
const scrollTop = appElement
? appElement.scrollTop
: window.pageYOffset || document.documentElement.scrollTop || 0;
const shouldBeScrolled = scrollTop > 100;
const shouldBeScrolled = scrollTop > 120;
if (this.isScrolled !== shouldBeScrolled) {
this.isScrolled = shouldBeScrolled;
}

View File

@@ -0,0 +1,187 @@
<!-- TEMPORARY SHARE TARGET DIAGNOSTICS -->
<!--
ShareTargetDebugView
Temporary, standalone debug panel for the iOS Share Target investigation.
Lets a tester dump and clear the native trace logs (share-extension-trace.log
and app-launch-trace.log) from the App Group container without attaching Xcode.
This entire view is temporary and intended to be deleted once the Share Target
investigation is complete. It does not change any share-target behavior.
-->
<template>
<QuickNav />
<!-- CONTENT -->
<section id="Content" class="p-6 pb-24 max-w-3xl mx-auto">
<!-- Sub View Heading -->
<div id="SubViewHeading" class="flex gap-4 items-start mb-8">
<h1 class="grow text-xl text-center font-semibold leading-tight">
Share Target Debug
</h1>
<!-- Back -->
<a
class="order-first text-lg text-center leading-none p-1"
@click="$router.go(-1)"
>
<font-awesome icon="chevron-left" class="block text-center w-[1em]" />
</a>
</div>
<p class="text-sm text-gray-600 mb-4">
Temporary diagnostics for the iOS Share Target investigation. Dumps the
native trace logs to the console and to the read-only fields below.
</p>
<!-- Action buttons -->
<div class="flex flex-wrap gap-2 mb-4">
<button :class="primaryButtonClasses" @click="dumpNativeTraces()">
Dump Native Traces
</button>
<button :class="warningButtonClasses" @click="clearExtensionTrace()">
Clear Share Extension Trace
</button>
<button :class="warningButtonClasses" @click="clearAppLaunchTrace()">
Clear App Launch Trace
</button>
</div>
<!-- Status message -->
<div
v-if="statusMessage"
class="mb-4 p-2 text-sm rounded-md bg-emerald-50 text-emerald-800 border border-emerald-200"
>
{{ statusMessage }}
</div>
<!-- Extension trace -->
<div class="mb-6">
<h2 class="text-lg font-semibold mb-2">Share Extension Trace</h2>
<textarea
:value="extensionTrace"
readonly
class="w-full h-64 p-2 border border-gray-300 rounded-md font-mono text-xs whitespace-pre overflow-auto"
placeholder="No extension trace loaded. Tap 'Dump Native Traces'."
></textarea>
</div>
<!-- App launch trace -->
<div class="mb-6">
<h2 class="text-lg font-semibold mb-2">App Launch Trace</h2>
<textarea
:value="appLaunchTrace"
readonly
class="w-full h-64 p-2 border border-gray-300 rounded-md font-mono text-xs whitespace-pre overflow-auto"
placeholder="No app launch trace loaded. Tap 'Dump Native Traces'."
></textarea>
</div>
</section>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import { Router } from "vue-router";
import QuickNav from "../components/QuickNav.vue";
import { SharedImage } from "../plugins/SharedImagePlugin";
import { logger } from "../utils/logger";
/**
* TEMPORARY SHARE TARGET DIAGNOSTICS
*
* Dedicated debug panel for inspecting the iOS Share Target native traces.
* Temporary; remove once the Share Target investigation is complete.
*/
@Component({
components: {
QuickNav,
},
})
export default class ShareTargetDebugView extends Vue {
$router!: Router;
// TEMPORARY SHARE TARGET DIAGNOSTICS
extensionTrace = "";
// TEMPORARY SHARE TARGET DIAGNOSTICS
appLaunchTrace = "";
// TEMPORARY SHARE TARGET DIAGNOSTICS
statusMessage = "";
// TEMPORARY SHARE TARGET DIAGNOSTICS
get primaryButtonClasses(): string {
return "font-bold capitalize bg-slate-500 text-white px-3 py-2 rounded-md";
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
get warningButtonClasses(): string {
return "font-bold capitalize bg-amber-600 text-white px-3 py-2 rounded-md";
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Retrieve both native traces, log them in full to the console, and display
* them in the read-only fields. Does not truncate either trace.
*/
async dumpNativeTraces(): Promise<void> {
try {
const extensionResult = await SharedImage.getShareExtensionTrace();
const launchResult = await SharedImage.getAppLaunchTrace();
this.extensionTrace = extensionResult.trace;
this.appLaunchTrace = launchResult.trace;
// Log full (untruncated) traces to the console.
console.info("[ShareTarget] EXTENSION TRACE START");
console.info(extensionResult.trace);
console.info("[ShareTarget] EXTENSION TRACE END");
console.info("");
console.info("[ShareTarget] APP LAUNCH TRACE START");
console.info(launchResult.trace);
console.info("[ShareTarget] APP LAUNCH TRACE END");
this.statusMessage =
"Dumped native traces (see console and fields below).";
} catch (error) {
logger.error("[ShareTarget] Failed to dump native traces:", error);
this.statusMessage = `Failed to dump native traces: ${
error instanceof Error ? error.message : String(error)
}`;
}
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Clear the native Share Extension trace log and the displayed value.
*/
async clearExtensionTrace(): Promise<void> {
try {
await SharedImage.clearShareExtensionTrace();
this.extensionTrace = "";
this.statusMessage = "Share Extension trace cleared.";
} catch (error) {
logger.error("[ShareTarget] Failed to clear extension trace:", error);
this.statusMessage = `Failed to clear Share Extension trace: ${
error instanceof Error ? error.message : String(error)
}`;
}
}
// TEMPORARY SHARE TARGET DIAGNOSTICS
/**
* Clear the native app launch trace log and the displayed value.
*/
async clearAppLaunchTrace(): Promise<void> {
try {
await SharedImage.clearAppLaunchTrace();
this.appLaunchTrace = "";
this.statusMessage = "App Launch trace cleared.";
} catch (error) {
logger.error("[ShareTarget] Failed to clear app launch trace:", error);
this.statusMessage = `Failed to clear App Launch trace: ${
error instanceof Error ? error.message : String(error)
}`;
}
}
}
</script>

View File

@@ -112,6 +112,21 @@
</router-link>
</div>
<!-- TEMPORARY SHARE TARGET DIAGNOSTICS -->
<div class="mt-8">
<h2 class="text-xl font-bold mb-4">Share Target Diagnostics</h2>
<p class="text-sm text-gray-600 mb-3">
Temporary debug panel for the iOS Share Target investigation (dump/clear
native traces).
</p>
<router-link
:to="{ name: 'share-target-debug' }"
class="block w-full text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md"
>
Open Share Target Debug Panel
</router-link>
</div>
<!-- URL Flow Testing Section -->
<div class="mt-8">
<h2 class="text-xl font-bold mb-4">URL Flow Testing</h2>