File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff line change 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 })))))
You can’t perform that action at this time.
0 commit comments