Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Create thumbnail on opening of a file (#2361)

Stanimirb90d25a83d67
diff --git a/release/app/package-lock.json b/release/app/package-lock.json
index 12ed0e0c7..0b7bd4590 100644
--- a/release/app/package-lock.json
+++ b/release/app/package-lock.json
@@ -11,14 +11,14 @@
"license": "AGPL-3.0",
"dependencies": {
"@elife/pm2": "3.6.1",
- "@tagspaces/extensions": "1.0.197",
+ "@tagspaces/extensions": "1.0.199",
"@tagspaces/tagspaces-common-node": "4.5.95",
"@tagspaces/tagspaces-ws": "4.5.95",
"sharp": "0.32.6",
"ws": "8.18.1"
},
"optionalDependencies": {
- "@tagspacespro/extensions": "2.0.5"
+ "@tagspacespro/extensions": "2.0.6"
}
},
"node_modules/@asamuzakjp/css-color": {
@@ -147,9 +147,9 @@
}
},
"node_modules/@tagspaces/extensions": {
- "version": "1.0.197",
- "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.197.tgz",
- "integrity": "sha512-Y0B2iyTMbqG9RgliWJY0zQAK6b28YYi5daEi6i3iic9fZakwDZ/puV8SAv1tSz0UzuSVsGR2T9mI9/vQ7iSn+g==",
+ "version": "1.0.199",
+ "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.199.tgz",
+ "integrity": "sha512-2OnUTUeJ2N++mv5NWDVZ8WlhuBawGsMX2q/IQCMud3iKMg+TWXqizdikK+NhjgYLSD0rnFdP/vZL3xaX7EhG+w==",
"dependencies": {
"shelljs": "^0.8.5",
"shx": "^0.3.4"
@@ -257,9 +257,9 @@
}
},
"node_modules/@tagspacespro/extensions": {
- "version": "2.0.5",
- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/extensions/2.0.5/e65ec6d2b410217d09a61de03f33fb4a9278449a",
- "integrity": "sha512-hQDt4Kbd4wdI+U/KR0KHOF+Vti02ICnwvDrE95KVeP/YZxzZsKwwpfwNLwy8cUP5y0avyKfshimbQ8TeShQd9g==",
+ "version": "2.0.6",
+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/extensions/2.0.6/73843c5058d410bb65fc1944008be63a7424c7c2",
+ "integrity": "sha512-QeitI5H3Y3oNkw+LnDKJudmLM+qNJs9Rej6CggMtku9693klNN/UrwR68MjRDCQah/jdLxfGt+zqyR9VRS4xaw==",
"optional": true,
"engines": {
"npm": ">= 6.14.15",
@@ -1882,9 +1882,9 @@
}
},
"@tagspaces/extensions": {
- "version": "1.0.197",
- "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.197.tgz",
- "integrity": "sha512-Y0B2iyTMbqG9RgliWJY0zQAK6b28YYi5daEi6i3iic9fZakwDZ/puV8SAv1tSz0UzuSVsGR2T9mI9/vQ7iSn+g==",
+ "version": "1.0.199",
+ "resolved": "https://registry.npmjs.org/@tagspaces/extensions/-/extensions-1.0.199.tgz",
+ "integrity": "sha512-2OnUTUeJ2N++mv5NWDVZ8WlhuBawGsMX2q/IQCMud3iKMg+TWXqizdikK+NhjgYLSD0rnFdP/vZL3xaX7EhG+w==",
"requires": {
"shelljs": "^0.8.5",
"shx": "^0.3.4"
@@ -1973,9 +1973,9 @@
}
},
"@tagspacespro/extensions": {
- "version": "2.0.5",
- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/extensions/2.0.5/e65ec6d2b410217d09a61de03f33fb4a9278449a",
- "integrity": "sha512-hQDt4Kbd4wdI+U/KR0KHOF+Vti02ICnwvDrE95KVeP/YZxzZsKwwpfwNLwy8cUP5y0avyKfshimbQ8TeShQd9g==",
+ "version": "2.0.6",
+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/extensions/2.0.6/73843c5058d410bb65fc1944008be63a7424c7c2",
+ "integrity": "sha512-QeitI5H3Y3oNkw+LnDKJudmLM+qNJs9Rej6CggMtku9693klNN/UrwR68MjRDCQah/jdLxfGt+zqyR9VRS4xaw==",
"optional": true
},
"@types/trusted-types": {
diff --git a/release/app/package.json b/release/app/package.json
index f295fbe36..977e3af98 100644
--- a/release/app/package.json
+++ b/release/app/package.json
@@ -18,13 +18,13 @@
},
"dependencies": {
"@elife/pm2": "3.6.1",
- "@tagspaces/extensions": "1.0.197",
+ "@tagspaces/extensions": "1.0.199",
"@tagspaces/tagspaces-common-node": "4.5.95",
"@tagspaces/tagspaces-ws": "4.5.95",
"sharp": "0.32.6",
"ws": "8.18.1"
},
"optionalDependencies": {
- "@tagspacespro/extensions": "2.0.5"
+ "@tagspacespro/extensions": "2.0.6"
}
}
diff --git a/src/renderer/components/EntryContainer.tsx b/src/renderer/components/EntryContainer.tsx
index 391fcb02b..d9e0d0fcc 100644
--- a/src/renderer/components/EntryContainer.tsx
+++ b/src/renderer/components/EntryContainer.tsx
@@ -54,6 +54,10 @@ import React, {
import { GlobalHotKeys } from 'react-hotkeys';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
+import { getResizedImageThumbnail } from '-/services/thumbsgenerator';
+import { base64ToBlob } from '-/utils/dom';
+import { useIOActionsContext } from '-/hooks/useIOActionsContext';
+import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';
function EntryContainer() {
const { t } = useTranslation();
@@ -72,6 +76,8 @@ function EntryContainer() {
useFilePropertiesContext();
const { findLocation } = useCurrentLocationContext();
const { saveFileOpen } = useResolveConflictContext();
+ const { setThumbnailImageChange } = useIOActionsContext();
+ const { saveBinaryFilePromise } = usePlatformFacadeContext();
const { showNotification, openConfirmDialog } = useNotificationContext();
const tabIndex = useSelector(getEntryContainerTab);
@@ -209,6 +215,37 @@ function EntryContainer() {
});
}
break;
+ case 'thumbnailGenerated':
+ if (data.content) {
+ getResizedImageThumbnail(data.content)
+ .then((base64Image) => {
+ const data = base64ToBlob(base64Image.split(',').pop());
+
+ const thumbPath = cLocation.getThumbEntryPath(openedEntry);
+ saveBinaryFilePromise(
+ { path: thumbPath },
+ data, //new Blob([data]), //data.buffer ? data.buffer :
+ true,
+ )
+ .then(() => {
+ return setThumbnailImageChange({
+ ...(openedEntry as TS.FileSystemEntry),
+ meta: { ...openedEntry.meta, thumbPath },
+ });
+ })
+ .catch((error) => {
+ console.error(
+ 'Save to file ' + openedEntry.path + ' failed ',
+ error,
+ );
+ return true;
+ });
+ })
+ .catch((error) => {
+ console.error('Thumbnail generation failed ' + error);
+ });
+ }
+ break;
case 'savingFile':
if (fileChanged) {
saveFile(data.content);