Skip to content

Commit

Permalink
[2.0.15/electron] picture import 가 차례대로 실행되도록 수정
Browse files Browse the repository at this point in the history
- canvas 오브젝트를 통해 변환을 요청하면서 병렬처리시 마지막에 그리기 요청된 데이터가 현재 대기중인 모든
  importPictureToTemp 의 convertSvg 이벤트에 다 쏴버림. 그래서 모두가 동일한 이미지 결과를 들고 돌아다님
  • Loading branch information
extracold1209 committed Nov 27, 2019
1 parent 4dd6573 commit 361a053
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/mainUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,18 @@ export default class MainUtils {
* @param sender
* @return {Promise<any[]>}
*/
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;
}

/**
Expand Down Expand Up @@ -678,8 +681,9 @@ export default class MainUtils {
static convertPng(filePath: string, sender: Electron.webContents): Promise<ConvertResult> {
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 에서 뽑아서 전달하지 않으면 코딱지만한 크기로 잡혀버린다.
Expand Down

0 comments on commit 361a053

Please sign in to comment.