PlatziDev / pulse

A Platzi Flavored Markdown desktop editor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Define `pulse` protocol to open markdown files from web

sergiodxa opened this issue · comments

We can handle pulse:// urls with the desktop app and allow us to open markdown files from web with the desktop app.

@demian-arenas so you want to do this? How do you plan to do implement it?

How do you think it will work the protocol? How to get the markdown content? URLs has a limit of characters so you can't just inline the content in the protocol.

My first idea was to take advantage of the 'Raw' option of Github to see files, put a simple URL like this

https://github.com/PlatziDev/pulse/blob/master/CODE_OF_CONDUCT.md

and convert to this

https://raw.githubusercontent.com/PlatziDev/pulse/master/CODE_OF_CONDUCT.md

then with simple Fetch API download the content. Use Github API to save the file. But I don't know if that's the better idea.

This was my idea with pulse://:

I go to a website which offer me a way to edit content as Markdown (e.g. Platzi) and they can give me a button with something like Edit on Pulse, that link should has a URL with the pulse protocol and if I have Pulse installed on my computer will open it with the content so I can update it there.

But it should work everywhere and it doesn't matter of the site and should be easy to implement for everysite.

I like the idea of using a simple URL and adding a RAW options so we could have pulse://domain.com/blog/my-post and then the editor could fetch it adding ?raw or something like that. I don't want to use a subdomain since it could require more work from the website using the protocol.

The way to implement it server side should be super simple with minimal work.

oh right, now I understand...

when you say 'client app' do you refer to pulse-editor, right? could be used something like this
function runPulse() { WshShell = new ActiveXObject('WScript.Shell') WshShell.Run('c:/url/to/pulse.exe') }
from pulse-editor, but that only open desktop app... could send the content as arguments to pulse.exe?

@demian-arenas Electron has a native way to define a protocol to be handled by the desktop app, I tried it before and it works but I didn't defined how it should work.

And with client app I mean Pulse (this pulse, not pulse-editor).

@sergiodxa What protocol method did you use?

Reading the protocol documentation I saw that you can use protocol.registerHttpProtocol (scheme, handler [, completion]) where the handler is a function with a request object and that support Post request, sending the data via uploadData. In the form of Buffer, could send the data with that option and response to web with message like 'The file is ready in Pulse'.

Here is the link about that protocol.registerHttpProtocol.

But, when a protocol is registered, is it still listening to with the closed app? or should have it open Pulse whenever you want to do that, or leave Pulse in the background with a small process waiting for the protocol event "pulse://"?

I think it was protocol.registerFileProtocol.

And yes it works even if the app is closed because the first time you open it is registered on the system.