mirror of
https://github.com/logseq/logseq.git
synced 2026-05-27 22:24:09 +00:00
fix(electron): compatible ipc for js object
This commit is contained in:
@@ -523,7 +523,9 @@
|
||||
(p/let [message (decode-main-ipc-message args-js)
|
||||
_ (vreset! message* message)
|
||||
result (handle (or (utils/get-win-from-sender event) window) message)]
|
||||
(sqlite-util/write-transit-str result))
|
||||
(if (= (last message) "js-obj")
|
||||
(bean/->js result)
|
||||
(sqlite-util/write-transit-str result)))
|
||||
(p/catch (fn [e]
|
||||
(let [command (command-name @message*)]
|
||||
(when-not (contains? #{"mkdir" "stat"} command)
|
||||
|
||||
@@ -11,12 +11,29 @@
|
||||
(sqlite-util/read-transit-str result)
|
||||
result))
|
||||
|
||||
(defn- js-pure-object?
|
||||
[x]
|
||||
(or (array? x)
|
||||
(and (some? x)
|
||||
(= "[object Object]"
|
||||
(.call (.-toString (.-prototype js/Object)) x))
|
||||
(let [prototype (js/Object.getPrototypeOf x)]
|
||||
(or (nil? prototype)
|
||||
(nil? (js/Object.getPrototypeOf prototype)))))))
|
||||
|
||||
(defn- has-js-obj?
|
||||
[args]
|
||||
(some js-pure-object? args))
|
||||
|
||||
(defn ipc
|
||||
[& args]
|
||||
(when (util/electron?)
|
||||
(p/let [payload (sqlite-util/write-transit-str (vec args))
|
||||
maybe-result-str (js/window.apis.doAction payload)]
|
||||
(maybe-read-transit maybe-result-str))))
|
||||
(if-let [args (and (has-js-obj? args)
|
||||
(conj (vec args) :js-obj))]
|
||||
(js/window.apis.doAction (bean/->js args))
|
||||
(p/let [payload (sqlite-util/write-transit-str args)
|
||||
maybe-result-str (js/window.apis.doAction payload)]
|
||||
(maybe-read-transit maybe-result-str)))))
|
||||
|
||||
(defn invoke
|
||||
[channel & args]
|
||||
|
||||
Reference in New Issue
Block a user