From 51da66bd6dc6c0269d0af9ff24ac83e7ccd61150 Mon Sep 17 00:00:00 2001 From: Eric Skogen Date: Fri, 6 Oct 2017 17:13:38 -0500 Subject: [PATCH] saveThumbnailFile always updates cache buster refactor saveThumbnailFile to be async --- src/js/window/main-window.js | 41 ++++++++++++++---------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/js/window/main-window.js b/src/js/window/main-window.js index c66c666dfa..d01db0fda6 100644 --- a/src/js/window/main-window.js +++ b/src/js/window/main-window.js @@ -1489,9 +1489,6 @@ let saveImageFile = async () => { // create/update the thumbnail image file if necessary let indexToSave = currentBoard // copy value if (shouldSaveThumbnail) { - // explicitly indicate to renderer that the file has changed - setEtag(path.join(boardPath, 'images', boardModel.boardFilenameForThumbnail(board))) - await saveThumbnailFile(indexToSave) await updateThumbnailDisplayFromFile(indexToSave) } @@ -1759,29 +1756,23 @@ const renderThumbnailToNewCanvas = (index, options = { forceReadFromFiles: false } } -const saveThumbnailFile = (index, options = { forceReadFromFiles: false }) => { - return new Promise((resolve, reject) => { - let imageFilePath = path.join(boardPath, 'images', boardModel.boardFilenameForThumbnail(boardData.boards[index])) +const saveThumbnailFile = async (index, options = { forceReadFromFiles: false }) => { + let imageFilePath = path.join(boardPath, 'images', boardModel.boardFilenameForThumbnail(boardData.boards[index])) - renderThumbnailToNewCanvas(index, options).then(canvas => { - let imageData = canvas - .toDataURL('image/png') - .replace(/^data:image\/\w+;base64,/, '') - - try { - fs.writeFile(imageFilePath, imageData, 'base64', () => { - console.log('saved thumbnail', imageFilePath, 'at index:', index) - resolve(index) - }) - } catch (err) { - console.error(err) - reject(err) - } - }).catch(err => { - console.log(err) - reject(err) - }) - }) + let canvas = await renderThumbnailToNewCanvas(index, options) + + // explicitly indicate to renderer that the file has changed + setEtag(imageFilePath) + + let imageData = canvas + .toDataURL('image/png') + .replace(/^data:image\/\w+;base64,/, '') + + fs.writeFileSync(imageFilePath, imageData, 'base64') + + console.log('saved thumbnail', imageFilePath, 'at index:', index) + + return index } const updateThumbnailDisplayFromFile = index => {