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

Predicate in sharing extension #3

Open
crspybits opened this issue Dec 28, 2020 · 1 comment
Open

Predicate in sharing extension #3

crspybits opened this issue Dec 28, 2020 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@crspybits
Copy link
Member

This is documentation for my future use.

If I just put this one:

    (
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.heic"
                ).@count == 1
            ).@count == 1
    )

then my extension is only "active" when a single image is selected. And by "active" I mean, is available in the UI as a choice. If I select a movie in Photos, it is not active. If I select a screen grab (PNG, I assume), it is not ative.
BUT: If I select a PNG and an image, it is active.


It looks like .@count == $extensionItem.attachments.@count may be the solution. When I use:

    (
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.heic"
                ).@count == $extensionItem.attachments.@count
            ).@count == 1
    )

If I select a PNG and an other (jpeg) image, my extension is not active. Though, if I select two live images, it is active.


When I do this, it seems improved:

            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.heic"
                ).@count == 1
            ).@count == 1
            
            AND
            
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.heic"
                ).@count == $extensionItem.attachments.@count
            ).@count == 1

a) If I select a single image, it is active.
b) Selecting two images, it is not active.
c) Selecting two live images, it is not active.
d) Selecting an image and a movie it is not active.


Now to try the parallel thing for url's (not going to worry about live images as that doesn't seem to work from sharing extensions):

        SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
            ).@count == $extensionItem.attachments.@count
        ).@count <= 2

This does allow images to be selected in Photos!


Trying this:

        SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
            ).@count <= 2
        ).@count <= 2

Same thing: This does allow images to be selected in Photos! Probably because of the <= 2 constraint.
0 is <= 2.


        SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
            ).(@count &lt;= 2 AND @count &gt;= 1)
        ).(@count &lt;= 2 AND @count &gt;= 1)

That's not allowing a URL to be selected in Safari.


        SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
            ).@count &lt;= 2
        ).@count &lt;= 2
 
        AND
        
         SUBQUERY (
            extensionItems,
            $extensionItem,
            SUBQUERY (
                $extensionItem.attachments,
                $attachment,
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
                ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
            ).@count &gt;=1
        ).@count &gt;=1  

That seems to do the trick!


Next to try to combine the two results:

		(
			SUBQUERY (
				extensionItems,
				$extensionItem,
				SUBQUERY (
					$extensionItem.attachments,
					$attachment,
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
				).@count &lt;= 2
			).@count &lt;= 2
			AND
			 SUBQUERY (
				extensionItems,
				$extensionItem,
				SUBQUERY (
					$extensionItem.attachments,
					$attachment,
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
				).@count &gt;=1
			).@count &gt;=1
        )
        OR
        (
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.heic"
                ).@count == 1
            ).@count == 1
            AND
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg" ||
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.heic"
                ).@count == $extensionItem.attachments.@count
            ).@count == 1
        )

This seems to work OK, but has a problem with some images labeled HDR in the simulator.


Try to remove HEIC since I'm not dealing with them as still images yet:

		(
			SUBQUERY (
				extensionItems,
				$extensionItem,
				SUBQUERY (
					$extensionItem.attachments,
					$attachment,
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
				).@count &lt;= 2
			).@count &lt;= 2
			AND
			 SUBQUERY (
				extensionItems,
				$extensionItem,
				SUBQUERY (
					$extensionItem.attachments,
					$attachment,
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url" ||
					ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.text"
				).@count &gt;=1
			).@count &gt;=1
        )
        OR
        (
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
                ).@count == 1
            ).@count == 1
            AND
            SUBQUERY (
                extensionItems,
                $extensionItem,
                SUBQUERY (
                    $extensionItem.attachments,
                    $attachment,
                    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
                ).@count == $extensionItem.attachments.@count
            ).@count == 1
        )

The same issue occurs with the same image. But it seems to work well enough so that's where I'm going to leave it for now.

@crspybits crspybits added the documentation Improvements or additions to documentation label Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant