From 361a0532da2d8a0a0db9a8d533cf41828752879c Mon Sep 17 00:00:00 2001 From: extracold1209 Date: Wed, 27 Nov 2019 14:16:32 +0900 Subject: [PATCH] =?UTF-8?q?[2.0.15/electron]=20picture=20import=20?= =?UTF-8?q?=EA=B0=80=20=EC=B0=A8=EB=A1=80=EB=8C=80=EB=A1=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - canvas 오브젝트를 통해 변환을 요청하면서 병렬처리시 마지막에 그리기 요청된 데이터가 현재 대기중인 모든 importPictureToTemp 의 convertSvg 이벤트에 다 쏴버림. 그래서 모두가 동일한 이미지 결과를 들고 돌아다님 --- src/main/mainUtils.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/mainUtils.ts b/src/main/mainUtils.ts index f123e043e..a850f45ec 100644 --- a/src/main/mainUtils.ts +++ b/src/main/mainUtils.ts @@ -438,15 +438,18 @@ export default class MainUtils { * @param sender * @return {Promise} */ - static importPicturesToTemp(filePaths: string[], sender: Electron.WebContents) { - return Promise.all(filePaths.map(async (filePath) => { + static async importPicturesToTemp(filePaths: string[], sender: Electron.WebContents) { + const results = []; + for (let i = 0; i < filePaths.length; i++) { + const filePath = filePaths[i]; const { filePath: newFilePath, svgPath } = await MainUtils.convertPng(filePath, sender); if (svgPath) { - return await MainUtils.importPictureToTemp(newFilePath, { svgPath }); + results.push(await MainUtils.importPictureToTemp(newFilePath, { svgPath })); } else { - return await MainUtils.importPictureToTemp(newFilePath); + results.push(await MainUtils.importPictureToTemp(newFilePath)); } - })); + } + return results; } /** @@ -678,8 +681,9 @@ export default class MainUtils { static convertPng(filePath: string, sender: Electron.webContents): Promise { return new Promise(async (resolve) => { try { + const newFileName = path.basename(filePath).replace(/\..*$/, ''); const fileData = await FileUtils.readFile(filePath, 'base64'); - const newFilePath = path.join(Constants.tempPathForExport('convert'), `${MainUtils.createFileId()}.png`); + const newFilePath = path.join(Constants.tempPathForExport('convert'), `${newFileName}.png`); const mimeType = mime.lookup(filePath); // svg 의 경우 viewBox 에서 뽑아서 전달하지 않으면 코딱지만한 크기로 잡혀버린다.