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

Support Swift Playgrounds #2

Merged
merged 10 commits into from
Jul 8, 2020
Merged

Support Swift Playgrounds #2

merged 10 commits into from
Jul 8, 2020

Conversation

liamnichols
Copy link
Contributor

@liamnichols liamnichols commented Jul 5, 2020

Hey! This is an awesome looking project and since it's all (mostly) written in Swift, it got me thinking about the ability to write shortcuts in Swift Playgrounds directly on the iPad 🧐

In theory, each time you publish a new release you could also publish a zipped .playgroundbook bundle that could then be opened into the Swift Playgrounds app on iPad allowing people to prototype shortcuts and use them all without having to use a Mac. Is this something you'd consider?

I did think that it was semi-pointless since you can just use Shortcuts anyway to create them using the GUI, but it might be useful for people who would prefer to express their shortcuts in code still?

This draft PR makes a few changes that result in a working POC. I've also included the gif below to show it in action:

SwiftShorcutsPlayground

(Note that I re-ran the playground because of what I think is an iOS 14 bug that broke the UIActivityViewController on first run but I need to confirm)

So yeah ... The changes to the project itself were pretty simple:

  1. Remove use of the Swift 5.2 compiler synthesised KeyPath methods (since Swift Playgrounds is currently still Swift 5.1
  2. Only use CSymbols for Linux as looking at commit history, they were only introduced to fix a linux crash I think (since Swift Playgrounds only supports Swift code)

Then in addition to that, I've included a .playgroundbook template that mostly resembles a blank playground with a few extras:

  1. The default page contains the Hello World example
  2. ShortcutsSupport module contains helpers to extend PlaygroundPage as well as an internal view controller that writes the shortcut to disk and lets it be shared via UIActivityViewController. Sharing on iOS kinda sucks but it does the job

There is then a GeneratePlayground.swift script that copies the template, sets it's version based on arguments and moves the package source code into a module within the .playgroundbook. The idea is that you could run this each time you make a release then zip the output SwiftShortcuts.playgroundbook and include on the GitHub release.

$ ./Playground/GeneratePlayground.swift -version 1.0.0 -debug false

Anyway ... I'd be keen to see what you think about this. I'm not the biggest user of Shortcuts in general but the second that I saw this library I really wanted to see if Swift Playgrounds could be pushed to its limits and it would be interesting to see what it might enable. Cheers!

@a2
Copy link
Owner

a2 commented Jul 5, 2020

Hey Liam, thank you for contributing the first external pull request! I'll definitely take a closer look at this soon. From what I see so far, this looks great and I definitely think this is something that should be included in the project. (I have to admit that I saw this PR coming since I had noticed that someone forked the repository. 😅)

@liamnichols
Copy link
Contributor Author

liamnichols commented Jul 5, 2020

The template playground file is just to save time, but in reality the entire .playgroundbook bundle could be generated from scratch. If you don't like the idea of the Playgrounds directory in the repo then it could be hosted in a different repo that uses something like Mint just to provide a cli that can be used to generate the bundle on each release


Hey Liam, thank you for contributing the first external pull request! I'll definitely take a closer look at this soon. From what I see so far, this looks great and I definitely think this is something that should be included in the project. (I have to admit that I saw this PR coming since I had noticed that someone forked the repository. 😅)

You're most welcome, no rush though, it was mostly just a weekend experiment 🙂

@a2
Copy link
Owner

a2 commented Jul 6, 2020

@liamnichols I see that this PR is still a "work in progress"? Let me know if/when you're done and I can review it more in-depth. Thank you again! 🙂

@liamnichols
Copy link
Contributor Author

@a2: ah my bad for the confusion, yep it's ready to discuss at least 🙂

@liamnichols liamnichols marked this pull request as ready for review July 6, 2020 15:44
Copy link
Owner

@a2 a2 left a comment

Choose a reason for hiding this comment

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

Thanks so much for your work! I think a lot of people will appreciate the ability to run this library through the Swift Playgrounds app 🙂

Comment on lines +122 to +128
return [
UIDragItem(
itemProvider: NSItemProvider(
object: ShortcutWrapper(shortcut)
)
)
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Annoyingly this doesn't actually seem to work for me when I try to drag the shortcut into the Shortcuts.app 😕
It does however work if I drag into the Files.app though so still worth keeping around.

I'm not sure if it relates to me running iOS 14 or not though since I get the green "+" indicator in the Shortcuts app but nothing happens when I drop (if I try with a different drag item (like text), I don't even get the green "+")

I might end up filing a feedback about this after I dig a little deeper as it would be a nice to have

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the code here should be working so i filled a Feedback about it... Might only be an iOS 14 bug still but worth keeping the code either way i think

@liamnichols
Copy link
Contributor Author

Thanks for the review @a2, I've updated the code and tested the new playground and all seems good still 👍

Copy link
Owner

@a2 a2 left a comment

Choose a reason for hiding this comment

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

Thanks for making the requested changes so quickly. Going to merge it now 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants