Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): retain shared URLs and track native share resources

Chris4b5f9d8679f4
diff --git a/apps/mobile/docs/incoming-sharing.md b/apps/mobile/docs/incoming-sharing.md
index 5789b982a9..2611f04915 100644
--- a/apps/mobile/docs/incoming-sharing.md
+++ b/apps/mobile/docs/incoming-sharing.md
@@ -43,6 +43,9 @@ new sending privileges: normal conversation hydration and authorization still ap
formats need no extension allowlist.
- `plugins/with-incoming-share-formats.js`: generated Expo controller integration.
Checked patch anchors fail prebuild if the upstream template changes.
+- `fingerprint.config.cjs`: explicitly hashes the share extension's Swift, strings
+ and Safari script resources. Register additional native resources here so format
+ changes invalidate cached binaries and require a compatible native release.
- `plugins/with-incoming-share-files.js`: App Group file ownership, activation predicate,
Safari script packaging and existing native-slot write/launch feedback. Expo Xcode
mods run in reverse registration order; keep this plugin before `expo-sharing`.
@@ -56,7 +59,8 @@ new sending privileges: normal conversation hydration and authorization still ap
API (latest 500 per computer plus pinned tasks); archived/worker/bot sessions are not
duplicated in the task section.
-Provider temporary URLs are copied **inside** the `loadFileRepresentation` callback.
+Provider temporary URLs are copied **inside** the `loadFileRepresentation` or
+`loadItem` callback. Web URLs precede image previews but follow concrete file exports.
Security-scoped access is balanced; directories use `NSFileCoordinator.forUploading`.
Each input owns a unique App Group directory, so equal filenames cannot overwrite.
The native slot is acknowledged only by the selected, focused, hydrated composer;
diff --git a/apps/mobile/fingerprint.config.cjs b/apps/mobile/fingerprint.config.cjs
index dfe515b246..8ee3ff172a 100644
--- a/apps/mobile/fingerprint.config.cjs
+++ b/apps/mobile/fingerprint.config.cjs
@@ -52,6 +52,14 @@ module.exports = {
reasons: ["native message menu assets"],
}))
.concat([
+ // These files are read by config plugins, then compiled/bundled into
+ // the share extension. Metro cannot update them on an installed binary.
+ ...[
+ "plugins/incoming-share-formats.swift",
+ "plugins/incoming-share-feedback.swift",
+ "plugins/incoming-share-strings.json",
+ "plugins/incoming-share-webpage.js",
+ ].map((filePath) => ({ type: "file", filePath, reasons: ["incoming share extension native resources"] })),
{
type: "dir",
filePath: "plugins/communication-notifications",
diff --git a/apps/mobile/plugins/incoming-share-formats.swift b/apps/mobile/plugins/incoming-share-formats.swift
index 102ae4a768..bd7f33e584 100644
--- a/apps/mobile/plugins/incoming-share-formats.swift
+++ b/apps/mobile/plugins/incoming-share-formats.swift
@@ -19,15 +19,17 @@
}
// Concrete exports win over thumbnails as well as text/link previews.
if let file = await loadShareFile(provider, format: .data, kind: .file, excludePlainText: true, excludeImages: true) { return file }
- if provider.hasItemConformingToTypeIdentifier(UTType.image.identifier),
- let image = await loadShareFile(provider, format: .image, kind: .image) { return image }
+ // Web links may also advertise a thumbnail; retain the actionable URL.
if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier),
let value = await loadShareItem(provider, identifier: UTType.url.identifier) {
- let url = (value as? URL) ?? (value as? String).flatMap(URL.init(string:))
+ let text = (value as? String) ?? (value as? Data).flatMap { String(data: $0, encoding: .utf8) }
+ let url = (value as? URL) ?? text.flatMap(URL.init(string:))
if let url, !url.isFileURL {
return SharePayload(type: .url, value: url.absoluteString, mimeType: "text/uri-list", metadata: nil)
}
}
+ if provider.hasItemConformingToTypeIdentifier(UTType.image.identifier),
+ let image = await loadShareFile(provider, format: .image, kind: .image) { return image }
if provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier),
let value = await loadShareItem(provider, identifier: UTType.plainText.identifier) {
let text = (value as? String) ?? (value as? NSAttributedString)?.string
diff --git a/apps/mobile/scripts/test-incoming-share-formats.mjs b/apps/mobile/scripts/test-incoming-share-formats.mjs
index c7d81b7b5a..39879d3b46 100644
--- a/apps/mobile/scripts/test-incoming-share-formats.mjs
+++ b/apps/mobile/scripts/test-incoming-share-formats.mjs
@@ -82,6 +82,17 @@ final class Adapter {
precondition(payload.type == .text && payload.value == "shared passage")
}
let selected = CommandLine.arguments[2]
+ let link = NSItemProvider()
+ let sharedURL = URL(string: "https://example.com/shared-page?source=provider")!
+ link.registerDataRepresentation(forTypeIdentifier: UTType.image.identifier, visibility: .all) { done in
+ done(Data("link thumbnail".utf8), nil); return nil
+ }
+ link.registerItem(forTypeIdentifier: UTType.url.identifier, loadHandler: { completion, _, _ in
+ completion?(sharedURL as NSURL, nil)
+ })
+ guard let linked = await adapter.parse(link) else { fatalError("Missing web URL") }
+ precondition(linked.type == .url && linked.value == sharedURL.absoluteString && linked.mimeType == "text/uri-list", "Thumbnail replaced web URL")
+ print("PASS: web URL survives its image thumbnail")
if selected != "file-url" {
for type in [UTType.pdf, .mpeg4Movie] {
let provider = NSItemProvider()
@@ -95,6 +106,9 @@ final class Adapter {
provider.registerDataRepresentation(forTypeIdentifier: type.identifier, visibility: .all) { done in
done(bytes, nil); return nil
}
+ provider.registerItem(forTypeIdentifier: UTType.url.identifier, loadHandler: { completion, _, _ in
+ completion?(sharedURL as NSURL, nil)
+ })
guard let payload = await adapter.parse(provider),
payload.type == (type.conforms(to: .movie) ? .video : .file),
let url = URL(string: payload.value) else { fatalError("Thumbnail replaced original export") }
diff --git a/apps/mobile/src/__tests__/fingerprintConfig.test.ts b/apps/mobile/src/__tests__/fingerprintConfig.test.ts
index a02f2360fc..f152f83702 100644
--- a/apps/mobile/src/__tests__/fingerprintConfig.test.ts
+++ b/apps/mobile/src/__tests__/fingerprintConfig.test.ts
@@ -187,3 +187,49 @@ describe("remote credentials fingerprint boundary", () => {
},
);
});
+
+it("changes the native fingerprint when incoming-share resources change", () => {
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
+ const config = require(CONFIG_PATH);
+ const resources = [
+ "plugins/incoming-share-formats.swift",
+ "plugins/incoming-share-feedback.swift",
+ "plugins/incoming-share-strings.json",
+ "plugins/incoming-share-webpage.js",
+ ];
+ const fixture = mkdtempSync(join(tmpdir(), "cindy-share-fingerprint-"));
+ try {
+ mkdirSync(join(fixture, "plugins"));
+ for (const resource of resources) {
+ cpSync(resolve(dirname(CONFIG_PATH), resource), join(fixture, resource));
+ }
+ const sources = config.extraSources.filter((source: { filePath: string }) => resources.includes(source.filePath));
+ const script = `
+ const fs = require('node:fs');
+ const path = require('node:path');
+ const { normalizeOptionsAsync } = require('@expo/fingerprint/build/Options');
+ const { createFingerprintFromSourcesAsync } = require('@expo/fingerprint/build/hash/Hash');
+ (async () => {
+ const root = process.argv[1];
+ const options = await normalizeOptionsAsync(root, { platforms: ['ios'], silent: true });
+ const hash = async () => (await createFingerprintFromSourcesAsync(${JSON.stringify(sources)}, root, options)).hash;
+ const baseline = await hash();
+ const changes = [];
+ for (const relative of ${JSON.stringify(resources)}) {
+ const file = path.join(root, relative);
+ const original = fs.readFileSync(file);
+ fs.appendFileSync(file, '\\n');
+ changes.push((await hash()) !== baseline);
+ fs.writeFileSync(file, original);
+ }
+ process.stdout.write(JSON.stringify(changes));
+ })().catch(error => { console.error(error); process.exitCode = 1; });
+ `;
+ const changed = JSON.parse(execFileSync(process.execPath, ["-e", script, fixture], {
+ cwd: dirname(CONFIG_PATH), encoding: "utf8", timeout: 15_000,
+ }));
+ expect(changed).toEqual(resources.map(() => true));
+ } finally {
+ rmSync(fixture, { recursive: true, force: true });
+ }
+});
diff --git a/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts b/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts
index bd9beac819..4092489841 100644
--- a/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts
+++ b/apps/mobile/src/__tests__/incomingShareNativePlugin.test.ts
@@ -154,6 +154,7 @@ it("preserves original exports ahead of previews and copies temporary URLs withi
expect(result.status).toBe(0);
expect(result.stdout).toContain("PASS: concrete Markdown/source files and plain text previews");
expect(result.stdout).toContain("PASS: original documents/videos beat thumbnails; real images remain images");
+ expect(result.stdout).toContain("PASS: web URL survives its image thumbnail");
expect(result.stdout).toContain("PASS: temporary file URL copied inside provider callback");
expect(result.stdout).toContain("PASS: durable exact-snapshot rejection, retry and replacement");
}, 180_000);