TagSpaces is an offline, open source, document manager with tagging support
fix: move pdf thumb generation in main windows
Ilian Sapundshiev4dbe7365c0d9
diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 1e323c17f..8d0c5e571 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -1523,7 +1523,8 @@ function prepareDirectoryContent(enhancedEntry.isFile && // only for filessettings.useGenerateThumbnails // enabled in the settings) {- if (isWorkerAvailable) {+ const isPDF = enhancedEntry.path.endsWith('.pdf');+ if (isWorkerAvailable && !isPDF) {tmbGenerationList.push(enhancedEntry.path);} else {tmbGenerationPromises.push(getThumbnailURLPromise(enhancedEntry.path));@@ -1563,23 +1564,20 @@ function prepareDirectoryContent(}dispatch(actions.setGeneratingThumbnails(false));- if (tmbGenerationPromises.length > 0) {+ if (tmbGenerationList.length > 0) {dispatch(actions.setGeneratingThumbnails(true));- // dispatch(actions.showNotification(i18n.t('core:checkingThumbnails'), 'info', false));- Promise.all(tmbGenerationPromises)+ PlatformIO.createThumbnailsInWorker(tmbGenerationList).then(handleTmbGenerationResults).catch(handleTmbGenerationFailed);}- if (tmbGenerationList.length > 0) {+ if (tmbGenerationPromises.length > 0) {dispatch(actions.setGeneratingThumbnails(true));- // dispatch(actions.showNotification(i18n.t('core:loadingOrGeneratingThumbnails'), 'info', false));- PlatformIO.createThumbnailsInWorker(tmbGenerationList)+ Promise.all(tmbGenerationPromises).then(handleTmbGenerationResults).catch(handleTmbGenerationFailed);}console.log('Dir ' + directoryPath + ' contains ' + directoryContent.length);- console.timeEnd('listDirectoryPromise');dispatch(actions.loadDirectorySuccess(directoryPath, directoryContent));}diff --git a/app/services/electron-io.ts b/app/services/electron-io.tsindex 77b5f881b..e7ace55c2 100644--- a/app/services/electron-io.ts+++ b/app/services/electron-io.ts@@ -250,15 +250,17 @@ export default class ElectronIO {createThumbnailsInWorker = (tmbGenerationList: Array<string>): Promise<any> =>new Promise((resolve, reject) => {+ const tmbGenChannel = 'TMB_GEN_CHANNEL';+ this.ipcRenderer.removeAllListeners(tmbGenChannel);if (this.isWorkerAvailable()) {- const timestamp = new Date().getTime().toString();this.workerWindow.webContents.send('worker', {- id: timestamp,+ id: tmbGenChannel,action: 'createThumbnails',tmbGenerationList});- this.ipcRenderer.once(timestamp, (event, data) => {- // console.log('Answer from worker received ' + data.result);+ this.ipcRenderer.on(tmbGenChannel, (event, data) => {+ // console.log('Answer from worker received!');+ // allSettled => data.result[].status === fulfilled // payload in valueresolve(data.result);});} else {@@ -280,7 +282,7 @@ export default class ElectronIO {let containsMetaFolder = false;// const metaMetaFolder = AppConfig.metaFolder + AppConfig.dirSeparator + AppConfig.metaFolder;if (path.startsWith('./')) {- //relative paths+ // relative pathspath = pathLib.resolve(path);}this.fs.readdir(path, (error, entries) => {diff --git a/app/splash-worker.ts b/app/splash-worker.tsindex a296f0bf5..5f76efeb3 100644--- a/app/splash-worker.ts+++ b/app/splash-worker.ts@@ -21,8 +21,6 @@ import { walkDirectory, enhanceEntry } from './services/utils-io';import AppConfig from './config';import { getThumbnailURLPromise } from './services/thumbsgenerator';-let isGeneratingThumbs = false;-function init() {console.log('Init worker');ipcRenderer.on('worker', (event, arg) => {@@ -89,11 +87,7 @@ function init() {}case 'createThumbnails': {console.log('createThumbnails started in worker window');- if (- !arg.tmbGenerationList ||- arg.tmbGenerationList.length < 1 ||- isGeneratingThumbs- ) {+ if (!arg.tmbGenerationList || arg.tmbGenerationList.length < 1) {ipcRenderer.send('worker', {id: arg.id,action: arg.action,@@ -102,32 +96,20 @@ function init() {});break;}- isGeneratingThumbs = true;const tmbGenerationPromises = [];- let splashShown = false;arg.tmbGenerationList.map(entry => {- if (!splashShown && entry.endsWith('pdf')) {- splashShown = true;- ipcRenderer.send('setSplashVisibility', {- visibility: true- });- }tmbGenerationPromises.push(getThumbnailURLPromise(entry));return true;});- Promise.all(tmbGenerationPromises)+ Promise.all(tmbGenerationPromises) // TODO check allSettled.then(tmbResult => {console.log('tmb results' + JSON.stringify(tmbResult));- ipcRenderer.send('setSplashVisibility', {- visibility: false- });ipcRenderer.send('worker', {id: arg.id,action: arg.action,result: tmbResult,error: ''});- isGeneratingThumbs = false;return true;}).catch(error => {@@ -138,10 +120,6 @@ function init() {result: [],error: 'Error generating thumbnails: ' + error});- ipcRenderer.send('setSplashVisibility', {- visibility: false- });- isGeneratingThumbs = false;});break;}