Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share Extension/Intents #2587

Merged
merged 48 commits into from
Feb 27, 2024
Merged

Conversation

haileyok
Copy link
Contributor

@haileyok haileyok commented Jan 21, 2024

fixes #66
fixes #1540

What I've tested

  • iOS
    • Share from Photos
    • Share screenshot
    • Share URL from Safari
    • Share text from selection
    • Share note (uses the note's text)
  • Android
    • Share from Photos
    • Share URL from Chrome
    • Share text from selection
    • Platforms 23, 25, 28, and 33
  • Web
    • Share text with ?compose=true&text=

Still to do

  • Probably should remove the copies of the images after everything is done (we have to wait until the post is actually made or discarded unfortunately otherwise we won't have access to the original image) - Later note: I'll handle this in a separate PR since we're migrating away from react-native-fs to expo-file-system and the logic will need to be different anyway.
Screen.Recording.2024-01-21.at.9.57.02.PM.mov

Intent

To open the composer, user navigates to https://bsky.app/intent/compose?text=Hello world!. The existing router logic handles passing those params to the home screen.

Native scheme

The same logic is used on native, allowing for bluesky://intent/compose?text=Hello world!.

In addition, image URIs from the extension are also allowed. These are passed in as imageUris?=uri1,uri2,uri3,uri4. Currently, only local URIs are supported.

Native share extension/module

On iOS we add an extension to the project's build phases. On Android, we add an expo module that handles the incoming intents for us and reroutes them to the correct scheme.

There's also a little script, updateExtensions.sh that updates the tracked native files in /modules/Share-with-Bluesky with the ones in /ios/Share-with-Bluesky, for development purposes, since unlike a module, the extension code needs to live inside of the ios directory.

Config plugin

In an effort to support the current prebuild configuration (ffs...🙃), an expo plugin handles moving the native code to the correct directories and adding the necessary build phases, entitlements, etc. to the projects. Config-defined schemes are supported, for those who may be doing their own testing in an effort to not overlap with the official build's scheme.

The Android build plugin just updates the AppManifest.xml with the necessary allowed intents.

@pfrazee
Copy link
Collaborator

pfrazee commented Jan 24, 2024

good gravy those build plugins

@haileyok
Copy link
Contributor Author

tfw writing the feature takes an hour and writing getting it to build takes a day

@haileyok haileyok marked this pull request as ready for review January 25, 2024 02:50
@haileyok
Copy link
Contributor Author

haileyok commented Jan 25, 2024

Feeling like this is probably ready to test out. I've tested the scenarios I can think of and they have all worked so far...

@pfrazee Still curious on whether you prefer to use bluesky:// or bsky://. I'm assuming the former since that's what was set in app.config.js but the router was looking for the bsky:// prefix. Here we use whatever is inside of app.config.js, so it will be bluesky://

@haileyok haileyok changed the title [WIP] Share Extension Share Extension/Intents Jan 25, 2024
@haileyok
Copy link
Contributor Author

haileyok commented Feb 6, 2024

Changing this to draft because I want to check over one thing I noticed (sharing an image that isn't in the photo gallery but rather from Safari or something) and I want to see what we're doing for intent URIs.

@haileyok haileyok marked this pull request as draft February 6, 2024 18:15
@haileyok haileyok mentioned this pull request Feb 27, 2024
@haileyok
Copy link
Contributor Author

Okay back to work.

@haileyok haileyok marked this pull request as ready for review February 27, 2024 20:27
Comment on lines +1 to +10
#!/bin/bash
IOS_SHARE_EXTENSION_DIRECTORY="./ios/Share-with-Bluesky"
MODULES_DIRECTORY="./modules"

if [ ! -d $IOS_SHARE_EXTENSION_DIRECTORY ]; then
echo "$IOS_SHARE_EXTENSION_DIRECTORY not found inside of your iOS project."
exit 1
else
cp -R $IOS_SHARE_EXTENSION_DIRECTORY $MODULES_DIRECTORY
fi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a helper script for updating the extension files inside of the ./modules directory with changes made in Xcode while dev/testing the extension.

Comment on lines +61 to +66
// For some security, we're going to filter out any image uri that is external. We don't want someone to
// be able to provide some link like "bluesky://intent/compose?imageUris=https://IHaveYourIpNow.com/image.jpeg
// and we load that image
if (part.includes('https://') || part.includes('http://')) {
return false
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this covers the main security concern with this. Any others I'm not considering?

openComposer({}) // will pass in values to the composer here in the share extension
openComposer({
text: text ?? undefined,
imageUris: isNative ? imageUris : undefined,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No support for imageUris on web for right now. At some point if we do allow external URLs through cardyb or something, we could do this.

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work Hailey. Narrowing it all down into the intent URL is very smart. Tested on simulators w/all platforms and felt great. So excited for this.

@pfrazee pfrazee merged commit d451f82 into bluesky-social:main Feb 27, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APP-870] Compose intent URL [APP-482] Add Bluesky as a "share to" target
3 participants