holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.49k stars 112 forks source link

Extension no longer has access to folders from `pickFolder` #729

Open n8gray opened 7 months ago

n8gray commented 7 months ago

I’m trying to build a shortcut that will do some git operations in another app’s sandbox.

IMG_0022

Thanks!

holzschu commented 7 months ago

From Apple's point of view, the App and the extension are two different apps, with different permissions. The extension does not have access to the same folders as the app (and reciprocally). They have a few bookmarks in common (~iCloud and ~shortcuts/~group), but that's it.

n8gray commented 7 months ago

Thanks for the reply! The "Working Copy" app makes this work somehow. You can make shortcuts that operate on a repo in the LogSeq sandbox without bringing Working Copy to the foreground. I suspect there's a way to configure your entitlements so that the extension and the app share these acquired permissions. I'll do some research this weekend and see if I can find the info.

holzschu commented 7 months ago

Thank you for pointing out that it was possible; I may have found out how to do it. I'm implementing it.

n8gray commented 7 months ago

Awesome, great to hear it.

n8gray commented 7 months ago

Hello again! Just curious - did you found a way to make this work?

holzschu commented 7 months ago

Not for now. I'm back to "I have no idea how this could work".

Emasoft commented 2 months ago

How Working Copy does it?

mdbraber commented 1 month ago

@holzschu do you have any pointers to what you thought might be the 'trick'? I'd like to do some digging in the Apple documentation to see what might be possible

holzschu commented 1 month ago

Apple documentation explicitly says that this is impossible. I have no idea how Anders Borum does it with WorkingCopy, and I think the only way to know would be to ask him directly.

mdbraber commented 1 month ago

@holzschu tnx - I first had to figure out what is exactly the Shortcut Item where this is used, but yes it indeed works in Working Copy (Pro Version):

  1. Create a new repository in Working Copy with "Link to external directory" and e.g. select On iPhone > Obsidian > Notes (which is my repository name in Obsidian) as the folder
  2. Create a Shortcut with an action "Get Repository Files", select the Repository Created and select the path to a test file e.g. /Test.md which is in my On iPhone > Obsidian > Notes directory
  3. Switch to Obsidian and make a test edit in the Test.md file
  4. Switch back to Shortcuts and run the Shortcut: it indeed shows the updated content!

So somehow Andreas is able to make this work (which is nifty!) Let's see if we can ask him if he would be able to shed some light on he is able to get this to work! https://mastodon.nl/@mdbraber/112433500468179009 @palmin

palmin commented 1 month ago

Working Copy will run most of its Shortcuts actions from the main binary (while staying in the background) as the memory limits are a little relaxed compared to an intent extension. A side effect is that security scoped bookmarks made by the main app work.

I'm not 100% sure this is the whole story but I would try this as a first thing.

mdbraber commented 1 month ago

Thanks for thinking along @palmin! I have to get a bit acquainted with the code (and Intents API), but would this mean that NSExtensionPointIdentifier would not be com.apple.intents-service or NSExtensionPrincipalClass has to be changed?

palmin commented 1 month ago

This video describes how to handle intents in the main app: https://developer.apple.com/wwdc20/10073

holzschu commented 1 month ago

Thank you for the explanation, @palmin! If the Shortcuts actions are run from the main app, not the extension, that explains everything.

mdbraber commented 1 month ago

With my limited knowledge of building iOS apps, this does seem rather possible as most of the Intent logic is already there. It seems that handling intents can be simplified as we don't need to repeat code as is now done in e.g. IntentHandler.

@holzschu what do you think? Would it be feasible to change from running apps in the extension to running from the main app?

WigsExp commented 1 month ago

I don't now how can't you do because may order coming department application az management thes all

holzschu commented 1 month ago

With my limited knowledge of building iOS apps, this does seem rather possible as most of the Intent logic is already there. It seems that handling intents can be simplified as we don't need to repeat code as is now done in e.g. IntentHandler.

@holzschu what do you think? Would it be feasible to change from running apps in the extension to running from the main app?

You already have the option to run Shortcuts "in app" instead of "in extension" (that's in the menu, and there's are three options: "default (use what you can)", "force in app", "force in extension"). The thing that is missing is the ability to run Shortcuts "in app but in the background". It seems technically feasible.

mdbraber commented 1 month ago

Absolutely right - I didn't make myself clear. I meant to ask if it's feasible to run Shortcuts "in app but in the background" as Anders mentioned. Would be great if this something which could be implemented.

n8gray commented 1 month ago

Great to hear this is feasible! I think a lot of workflows could benefit from the ability to run in-app without bringing the app to foreground.

mdbraber commented 1 month ago

image

I've got it working in XCode / development - I'll clean up the code, test some more and submit a PR

holzschu commented 3 weeks ago

The TestFlight version ( https://testflight.apple.com/join/REdHww5C ) had the PR by @mdbraber and offers the possibility to run Shortcuts commands "in the app but in the background", so you can access the bookmarks created by pickFolder (and also run Python packages and Python commands).

mdbraber commented 3 weeks ago

Thanks @palmin for the pointer in the right direction!