I would like to develop a plugin and make use of the logseq:// protocol handler. Unfortunately it seems to me, that this is not supported yet.
All existing handlers seems not to be working, or at least I have no idea how to use them to pass it to my plugin (yet):
In src/electron/electron/url.cljs
(defn logseq-url-handler
"win - the main window"
[^js win parsed-url]
(let [url-host (.-host parsed-url)] ;; return "" when no pathname provided
(cond
(= "x-callback-url" url-host)
(x-callback-url-handler win parsed-url)
;; identifier of graph in local
(= "graph" url-host)
(local-url-handler win parsed-url false)
(= "new-window" url-host)
(local-url-handler win parsed-url true)
(= "handbook" url-host)
(send-to-renderer :handbook
{:key (some-> (.-pathname parsed-url) (string/replace-first #"^[\/]+" ""))
:args (some-> (.-searchParams parsed-url) (js/Object.fromEntries))})
Looks like we would need to add a custom handler for plugins, so they can make use of it and execute functions. Anybody knows how to do it or if I can use existing handler? I tried several things on plugin-side so far, but nothing worked.
I try to implement an OAUTH 2.0 login flow to X/Twitter API from within logseq, which would require that the API can redirect to my custom logseq handler to finish the login (to connect X with logseq). Otherwise I need to start a local http server if this is possible to process the request instead.
Bookmarks at the moment. It requires OAuth 2.0 PKCE flow. Yeah the easiest would be if logseq plugin API could support custom handling of the logseq protocol.
I tried my best the last days to add this feature in logseq, but I’m giving up for now. CLJS and logseq architecture would require much more time to understand it better. Maybe someone can take this over and finish it. I gave it two tries but the last step Callback from CLJS → Calling callback of my custom extension always failed. No idea why and I’m happy if I can use the protocol handler one day for plugin to interact with other applications.
1st try (no need to check it):
2nd try:
Use in plugin would be:
logseq.onProtocolHandle('twitter-oauth-callback', (params: Record<string, string>) => {
console.log('[TwitterModule] OAuth callback detected', params);
}); // or logseq.App would fit better maybe