fix: quick capture across desktops

This commit is contained in:
Junyi Du
2022-07-08 00:31:54 +08:00
parent 3b383a918b
commit 872c185eb7
3 changed files with 24 additions and 12 deletions

View File

@@ -43,6 +43,8 @@
:win win})))
(defn open-url-handler
"win - the main window instance (first renderer process)
url - the input URL"
[win url]
(.info logger "open-url" (str {:url url}))

View File

@@ -2,7 +2,7 @@
(:require [electron.handler :as handler]
[electron.state :as state]
[electron.window :as win]
[electron.utils :refer [send-to-renderer] :as utils]
[electron.utils :refer [send-to-renderer send-to-focused-renderer] :as utils]
[clojure.string :as string]
[promesa.core :as p]))
@@ -58,22 +58,24 @@
(graph-identifier-error-handler graph-identifier))))
(defn- x-callback-url-handler
[^js parsed-url]
"win - a window used for fallback (main window is prefered)"
[^js win parsed-url]
(let [action (.-pathname parsed-url)]
(cond
(= action "/quickCapture")
(let [[url title content] (get-URL-decoded-params parsed-url ["url" "title" "content"])]
(send-to-renderer "quickCapture" {:url url
:title title
:content content}))
(send-to-focused-renderer "quickCapture" {:url url
:title title
:content content} win))
:else
(send-to-renderer "notification" {:type "error"
:payload (str "Unimplemented x-callback-url action: `"
action
"`.")}))))
(send-to-focused-renderer "notification" {:type "error"
:payload (str "Unimplemented x-callback-url action: `"
action
"`.")} win))))
(defn logseq-url-handler
"win - the main window"
[^js win parsed-url]
(let [url-host (.-host parsed-url)] ;; return "" when no pathname provided
(cond
@@ -81,7 +83,7 @@
(send-to-renderer win "loginCallback" (.get (.-searchParams parsed-url) "code"))
(= "x-callback-url" url-host)
(x-callback-url-handler parsed-url)
(x-callback-url-handler win parsed-url)
;; identifier of graph in local
(= "graph" url-host)

View File

@@ -6,7 +6,7 @@
[cljs-bean.core :as bean]
["electron" :refer [app BrowserWindow]]))
(defonce *win (atom nil))
(defonce *win (atom nil)) ;; The main window
(defonce mac? (= (.-platform js/process) "darwin"))
(defonce win32? (= (.-platform js/process) "win32"))
(defonce linux? (= (.-platform js/process) "linux"))
@@ -112,7 +112,8 @@
(defn send-to-renderer
"Notice: pass the `window` parameter if you can. Otherwise, the message
will not be received if there's no focused window."
will not be received if there's no focused window.
Use `send-to-focused-renderer` instead if you want to set a window for fallback"
([kind payload]
(send-to-renderer (get-focused-window) kind payload))
([window kind payload]
@@ -120,6 +121,13 @@
(.. ^js window -webContents
(send (name kind) (bean/->js payload))))))
(defn send-to-focused-renderer
"Try to send to focused window. If no focused window, fallback to the `fallback-win`"
([kind payload fallback-win]
(let [focused-win (get-focused-window)
win (if focused-win focused-win fallback-win)]
(send-to-renderer win kind payload))))
(defn get-graph-dir
"required by all internal state in the electron section"
[graph-name]