mirror of
https://github.com/logseq/logseq.git
synced 2026-05-24 04:34:14 +00:00
fix: Can't copy image in desktop
Addresses one of the issues in https://github.com/logseq/db-test/issues/792
This commit is contained in:
@@ -259,10 +259,32 @@
|
||||
[:<>
|
||||
(let [handle-copy!
|
||||
(fn [_e]
|
||||
(-> (util/copy-image-to-clipboard image-src)
|
||||
(p/then #(notification/show! "Copied!" :success))
|
||||
(p/catch (fn [error]
|
||||
(js/console.error error)))))
|
||||
;; Electron renderer cannot fetch file:// URLs; read the
|
||||
;; file via IPC and copy the blob directly.
|
||||
(if (util/electron?)
|
||||
(let [ext (some-> (util/get-file-ext image-src) string/lower-case)
|
||||
;; Should support all exts in common-config/img-formats
|
||||
ext->mime {"png" "image/png"
|
||||
"jpg" "image/jpeg"
|
||||
"jpeg" "image/jpeg"
|
||||
"gif" "image/gif"
|
||||
"webp" "image/webp"
|
||||
"bmp" "image/bmp"
|
||||
"svg" "image/svg+xml"
|
||||
"ico" "image/x-icon"}
|
||||
mime (get ext->mime ext)]
|
||||
(if-not mime
|
||||
(notification/show! (str "Copy image is not supported for ." ext " files") :warning)
|
||||
(-> (p/let [binary (fs/read-file-raw nil image-src {})
|
||||
blob (js/Blob. (array binary) (clj->js {:type mime}))]
|
||||
(util/copy-image-blob-to-clipboard blob))
|
||||
(p/then #(notification/show! "Copied!" :success))
|
||||
(p/catch (fn [error]
|
||||
(js/console.error error))))))
|
||||
(-> (util/copy-image-to-clipboard src')
|
||||
(p/then #(notification/show! "Copied!" :success))
|
||||
(p/catch (fn [error]
|
||||
(js/console.error error))))))
|
||||
handle-delete!
|
||||
(fn [_e]
|
||||
(when-let [block-id (get-blockid)]
|
||||
|
||||
@@ -1314,16 +1314,20 @@
|
||||
(.catch (fn [err]
|
||||
(js/console.error "Web clipboard failed" err)))))))))
|
||||
|
||||
#?(:cljs
|
||||
(defn copy-image-blob-to-clipboard
|
||||
[blob]
|
||||
(if (= (.-type blob) "image/png")
|
||||
(write-blob-to-clipboard blob)
|
||||
(image-blob->png blob write-blob-to-clipboard))))
|
||||
|
||||
#?(:cljs
|
||||
(defn copy-image-to-clipboard
|
||||
[src]
|
||||
(-> (js/fetch src)
|
||||
(.then (fn [data]
|
||||
(-> (.blob data)
|
||||
(.then (fn [blob]
|
||||
(if (= (.-type blob) "image/png")
|
||||
(write-blob-to-clipboard blob)
|
||||
(image-blob->png blob write-blob-to-clipboard))))
|
||||
(.then copy-image-blob-to-clipboard)
|
||||
(.catch js/console.error)))))))
|
||||
|
||||
(defn memoize-last
|
||||
|
||||
Reference in New Issue
Block a user