cp
This commit is contained in:
parent
1f5fbcae76
commit
76be5e37d5
3 changed files with 25 additions and 43 deletions
|
@ -180,11 +180,11 @@ const percentageSizeDiff = (
|
|||
* app, and this dependency is enforced by the need to pass the {@link electron}
|
||||
* object which we use to perform IPC with the Node.js side of our desktop app.
|
||||
*
|
||||
* @param dataOrPath The image or video {@link File}, or the path to the image
|
||||
* or video file on the user's local filesystem, whose thumbnail we want to
|
||||
* generate.
|
||||
* @param dataOrPath Contents of an image or video file, or the path to the
|
||||
* image or video file on the user's local filesystem, whose thumbnail we want
|
||||
* to generate.
|
||||
*
|
||||
* @param fileTypeInfo The type information for {@link fileOrPath}.
|
||||
* @param fileTypeInfo The type information for {@link dataOrPath}.
|
||||
*
|
||||
* @return The JPEG data of the generated thumbnail.
|
||||
*
|
||||
|
@ -192,39 +192,16 @@ const percentageSizeDiff = (
|
|||
*/
|
||||
export const generateThumbnailNative = async (
|
||||
electron: Electron,
|
||||
fileOrPath: File | string,
|
||||
dataOrPath: Uint8Array | string,
|
||||
fileTypeInfo: FileTypeInfo,
|
||||
): Promise<Uint8Array> =>
|
||||
fileTypeInfo.fileType === FILE_TYPE.IMAGE
|
||||
? await generateImageThumbnailNative(electron, fileOrPath)
|
||||
: await generateVideoThumbnailNative(blob);
|
||||
|
||||
const generateImageThumbnailNative = async (
|
||||
electron: Electron,
|
||||
fileOrPath: File | string,
|
||||
) => {
|
||||
const startTime = Date.now();
|
||||
const jpegData = await electron.generateImageThumbnail(
|
||||
fileOrPath instanceof File
|
||||
? new Uint8Array(await fileOrPath.arrayBuffer())
|
||||
: fileOrPath,
|
||||
maxThumbnailDimension,
|
||||
maxThumbnailSize,
|
||||
);
|
||||
log.debug(
|
||||
() => `Native thumbnail generation took ${Date.now() - startTime} ms`,
|
||||
);
|
||||
return jpegData;
|
||||
};
|
||||
|
||||
const dataOrPath = (fileOrPath) => {
|
||||
fileOrPath
|
||||
}
|
||||
const generateVideoThumbnailNative = async (
|
||||
electron: Electron,
|
||||
fileOrPath: File | string,
|
||||
) => ffmpeg.generateVideoThumbnailNative(electron, )
|
||||
|
||||
? await electron.generateImageThumbnail(
|
||||
dataOrPath,
|
||||
maxThumbnailDimension,
|
||||
maxThumbnailSize,
|
||||
)
|
||||
: ffmpeg.generateVideoThumbnailNative(electron, dataOrPath);
|
||||
|
||||
/**
|
||||
* A fallback, black, thumbnail for use in cases where thumbnail generation
|
||||
|
|
|
@ -364,13 +364,15 @@ const readAsset = async (
|
|||
class ModuleState {
|
||||
/**
|
||||
* This will be set to true if we get an error from the Node.js side of our
|
||||
* desktop app telling us that native JPEG conversion is not available for
|
||||
* the current OS/arch combination. That way, we can stop pestering it again
|
||||
* and again (saving an IPC round-trip).
|
||||
* desktop app telling us that native image thumbnail generation is not
|
||||
* available for the current OS/arch combination.
|
||||
*
|
||||
* That way, we can stop pestering it again and again (saving an IPC
|
||||
* round-trip).
|
||||
*
|
||||
* Note the double negative when it is used.
|
||||
*/
|
||||
isNativeThumbnailCreationNotAvailable = false;
|
||||
isNativeImageThumbnailCreationNotAvailable = false;
|
||||
}
|
||||
|
||||
const moduleState = new ModuleState();
|
||||
|
@ -429,7 +431,8 @@ const readFileOrPath = async (
|
|||
): Promise<FileInMemory> => {
|
||||
log.info(`Reading file ${fopLabel(fileOrPath)} `);
|
||||
|
||||
// If it's a file, read it into data
|
||||
// If it's a file, read-in its data. We need to do it once anyway for
|
||||
// generating the thumbnail.
|
||||
const dataOrPath =
|
||||
fileOrPath instanceof File
|
||||
? new Uint8Array(await fileOrPath.arrayBuffer())
|
||||
|
@ -438,8 +441,8 @@ const readFileOrPath = async (
|
|||
let thumbnail: Uint8Array;
|
||||
|
||||
const electron = globalThis.electron;
|
||||
const available = !moduleState.isNativeThumbnailCreationNotAvailable;
|
||||
if (electron && available) {
|
||||
if (electron) {
|
||||
if !moduleState.isNativeImageThumbnailCreationNotAvailable;
|
||||
try {
|
||||
return await generateImageThumbnailNative(electron, fileOrPath);
|
||||
} catch (e) {
|
||||
|
|
|
@ -62,8 +62,10 @@ class ModuleState {
|
|||
/**
|
||||
* This will be set to true if we get an error from the Node.js side of our
|
||||
* desktop app telling us that native JPEG conversion is not available for
|
||||
* the current OS/arch combination. That way, we can stop pestering it again
|
||||
* and again (saving an IPC round-trip).
|
||||
* the current OS/arch combination.
|
||||
*
|
||||
* That way, we can stop pestering it again and again (saving an IPC
|
||||
* round-trip).
|
||||
*
|
||||
* Note the double negative when it is used.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue