Skip to content

Commit 8290108

Browse files
fix: drag n drop asset doesn't work in electron
Last console error was "Error: No protocol method ICounted.-count defined for type object: [object ArrayBuffer]"
1 parent 09b5980 commit 8290108

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

resources/js/preload.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ contextBridge.exposeInMainWorld('apis', {
135135
return await ipcRenderer.invoke('call-main-win', type, ...args)
136136
},
137137

138+
/**
139+
* Write binary data to a file, creating parent dirs as needed.
140+
* Used for asset files that can't be transit-serialized through doAction.
141+
*/
142+
writeFileBytes (filePath, data) {
143+
const dir = path.dirname(filePath)
144+
fs.mkdirSync(dir, { recursive: true })
145+
fs.writeFileSync(filePath, Buffer.from(data))
146+
},
147+
138148
getFilePathFromClipboard,
139149

140150
getClipboardData,

src/main/frontend/fs.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@
121121
(if (util/electron?)
122122
(let [assets-dir (path/path-join repo-dir common-config/local-assets-dir)
123123
file-path (path/path-join assets-dir file-name)]
124-
(write-file! file-path data))
124+
;; Use writeFileBytes directly instead of ipc/ipc (write-file!) because
125+
;; binary data like ArrayBuffer can't be transit-serialized
126+
(js/window.apis.writeFileBytes file-path data))
125127
(let [file-path (path/path-join common-config/local-assets-dir file-name)]
126128
(write-plain-text-file! repo repo-dir file-path data {:skip-transact? true
127129
:skip-compare? true})))))

0 commit comments

Comments
 (0)