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

Register custom browser protocols for .pdez and .pdex files #559

Closed
SableRaf opened this issue Sep 23, 2022 · 8 comments
Closed

Register custom browser protocols for .pdez and .pdex files #559

SableRaf opened this issue Sep 23, 2022 · 8 comments
Labels
Enhancement New feature or request

Comments

@SableRaf
Copy link
Contributor

Since Processing 4.0, you can bundle sketches as double-clickable .pdez files and Libraries/Modes/Tools as .pdex files for easy sharing and installation. (see Processing #73, Processing #3987, and the release notes for 4.0 beta1)

A great next step would be to allow .pdez and .pdex files to be opened in the PDE directly from a url in a web browser. This would enable easier sharing of sketches on the forum, better UX for multi-tab examples on the website, and open the possibility for online Processing sketch galleries.

This would require the user to register the protocol on their system (which I imagine could be done from the PDE ?) For example, this page describes the steps needed to register a custom browser protocol on Window, macOS and Linux. There is also a W3C documentation page about custom scheme and content handlers.

@SableRaf
Copy link
Contributor Author

On a side note, we may need to warn people to only run code when they trust the author (similar to VSCode's restricted mode)

image

@benfry
Copy link
Member

benfry commented Sep 23, 2022

That should be in place because the file extension mapping should be happening. Is that not working?

For the second point, can you open a separate issue? Or perhaps even before that, have you tried it to see what it says now? I realize it's not making a stink about the security implications, but it should already be prompting whether you meant to open it or not.

@SableRaf
Copy link
Contributor Author

It works as intended if you download the file then open it.

I was talking about opening the file directly by clicking a link in the form processing4://my-website.com/sketch220924.pdez in the browser. This requires an extra step of registering the URI scheme at the OS level. If Processing already does that I couldn't find it in core.

@SableRaf
Copy link
Contributor Author

SableRaf commented Sep 24, 2022

I did some more research.

On macOS at least, the first step is adding the protocol name and scheme to the info.plist file. For example:

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLName</key>
		<string>Processing 4</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>processing4</string>
		</array>
	</dict>
</array>

Then there needs to be a handler for these URLs in the PDE code using setOpenURIHandler from what I understand (which is admittedly very little).

References:

@benfry
Copy link
Member

benfry commented Sep 25, 2022

You can just use http:// or https:// URLs, no need to do a special protocol handler.

@SableRaf
Copy link
Contributor Author

SableRaf commented Oct 6, 2022

I made a quick test to show the current behavior: https://sableraf.github.io/testURIscheme/

http:// or https:// links trigger the browser to download the file (tested on Windows 10 and macOS 12.5.1)

Note: I also included a placeholder link with a processingOrg:// custom protocol for future testing.

@benfry
Copy link
Member

benfry commented Feb 18, 2023

Implemented for macOS and Windows for 4.2; uses pde:// and can point to a local file or an https url online. More to come…

@benfry benfry closed this as completed Feb 18, 2023
@benfry benfry added the Enhancement New feature or request label Feb 18, 2023
@benfry benfry changed the title [Feature request] Registering custom browser protocols for .pdez and .pdex files Registering custom browser protocols for .pdez and .pdex files Feb 18, 2023
@benfry benfry changed the title Registering custom browser protocols for .pdez and .pdex files Register custom browser protocols for .pdez and .pdex files Feb 18, 2023
@SableRaf
Copy link
Contributor Author

Thanks @benfry this is amazing! Shoutout to @opyh for initially suggesting the idea in a conversation we had back in August.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants