Merge pull request #141 from ente-io/update-image-processor-error-handling
Update image processor error handling
This commit is contained in:
commit
16d5f5510e
|
@ -1,10 +1,15 @@
|
|||
import { CustomErrors } from '../constants/errors';
|
||||
import { ipcRenderer } from 'electron/renderer';
|
||||
import { existsSync } from 'fs';
|
||||
import { writeStream } from '../services/fs';
|
||||
import { logError } from '../services/logging';
|
||||
import { ElectronFile } from '../types';
|
||||
import { isPlatform } from '../utils/common/platform';
|
||||
|
||||
export async function convertHEIC(fileData: Uint8Array): Promise<Uint8Array> {
|
||||
if (isPlatform('windows')) {
|
||||
throw Error(CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED);
|
||||
}
|
||||
const convertedFileData = await ipcRenderer.invoke(
|
||||
'convert-heic',
|
||||
fileData
|
||||
|
@ -20,6 +25,11 @@ export async function generateImageThumbnail(
|
|||
let inputFilePath = null;
|
||||
let createdTempInputFile = null;
|
||||
try {
|
||||
if (isPlatform('windows')) {
|
||||
throw Error(
|
||||
CustomErrors.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED
|
||||
);
|
||||
}
|
||||
if (!existsSync(inputFile.path)) {
|
||||
const tempFilePath = await ipcRenderer.invoke(
|
||||
'get-temp-file-path',
|
||||
|
|
5
src/constants/errors.ts
Normal file
5
src/constants/errors.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
export const CustomErrors = {
|
||||
WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED:
|
||||
'Windows native image processing is not supported',
|
||||
INVALID_OS: (os: string) => `Invalid OS - ${os}`,
|
||||
};
|
|
@ -12,7 +12,7 @@ import {
|
|||
import fetch from 'node-fetch';
|
||||
import { logErrorSentry } from './sentry';
|
||||
import ElectronLog from 'electron-log';
|
||||
import { isPlatform } from '../utils/main';
|
||||
import { isPlatform } from '../utils/common/platform';
|
||||
|
||||
const FIVE_MIN_IN_MICROSECOND = 5 * 60 * 1000;
|
||||
const ONE_DAY_IN_MICROSECOND = 1 * 24 * 60 * 60 * 1000;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { isPlatform } from '../utils/main';
|
||||
import { isPlatform } from '../utils/common/platform';
|
||||
import { AutoLauncherClient } from '../types/autoLauncher';
|
||||
import linuxAutoLauncher from './autoLauncherClients/linuxAutoLauncher';
|
||||
import macAndWindowsAutoLauncher from './autoLauncherClients/macAndWindowsAutoLauncher';
|
||||
|
|
|
@ -5,10 +5,11 @@ import { existsSync, rmSync } from 'fs';
|
|||
import { readFile, writeFile } from 'promise-fs';
|
||||
import { generateTempFilePath } from '../utils/temp';
|
||||
import { logErrorSentry } from './sentry';
|
||||
import { isPlatform } from '../utils/main';
|
||||
import { isPlatform } from '../utils/common/platform';
|
||||
import { isDev } from '../utils/common';
|
||||
import path from 'path';
|
||||
import log from 'electron-log';
|
||||
import { CustomErrors } from '../constants/errors';
|
||||
const shellescape = require('any-shell-escape');
|
||||
|
||||
const asyncExec = util.promisify(exec);
|
||||
|
@ -157,7 +158,7 @@ function constructConvertCommand(
|
|||
}
|
||||
);
|
||||
} else {
|
||||
Error(`${process.platform} native heic convert not supported yet`);
|
||||
throw Error(CustomErrors.INVALID_OS(process.platform));
|
||||
}
|
||||
return convertCmd;
|
||||
}
|
||||
|
@ -271,9 +272,7 @@ function constructThumbnailGenerationCommand(
|
|||
return cmdPart;
|
||||
});
|
||||
} else {
|
||||
Error(
|
||||
`${process.platform} native thumbnail generation not supported yet`
|
||||
);
|
||||
throw Error(CustomErrors.INVALID_OS(process.platform));
|
||||
}
|
||||
return thumbnailGenerationCmd;
|
||||
}
|
||||
|
|
11
src/utils/common/platform.ts
Normal file
11
src/utils/common/platform.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export function isPlatform(platform: 'mac' | 'windows' | 'linux') {
|
||||
if (process.platform === 'darwin') {
|
||||
return platform === 'mac';
|
||||
} else if (process.platform === 'win32') {
|
||||
return platform === 'windows';
|
||||
} else if (process.platform === 'linux') {
|
||||
return platform === 'linux';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ import * as path from 'path';
|
|||
import { isDev } from './common';
|
||||
import { isAppQuitting } from '../main';
|
||||
import { PROD_HOST_URL } from '../config';
|
||||
import { isPlatform } from './main';
|
||||
import { isPlatform } from './common/platform';
|
||||
import { getHideDockIconPreference } from '../services/userPreference';
|
||||
import autoLauncher from '../services/autoLauncher';
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import { getHideDockIconPreference } from '../services/userPreference';
|
|||
import { setupAutoUpdater } from '../services/appUpdater';
|
||||
import ElectronLog from 'electron-log';
|
||||
import os from 'os';
|
||||
import { isPlatform } from './common/platform';
|
||||
|
||||
export function handleUpdates(mainWindow: BrowserWindow) {
|
||||
if (!isDev) {
|
||||
|
@ -84,18 +85,6 @@ export function setupNextElectronServe() {
|
|||
});
|
||||
}
|
||||
|
||||
export function isPlatform(platform: 'mac' | 'windows' | 'linux') {
|
||||
if (process.platform === 'darwin') {
|
||||
return platform === 'mac';
|
||||
} else if (process.platform === 'win32') {
|
||||
return platform === 'windows';
|
||||
} else if (process.platform === 'linux') {
|
||||
return platform === 'linux';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleDockIconHideOnAutoLaunch() {
|
||||
const shouldHideDockIcon = getHideDockIconPreference();
|
||||
const wasAutoLaunched = await autoLauncher.wasAutoLaunched();
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
} from '../services/userPreference';
|
||||
import { setIsAppQuitting } from '../main';
|
||||
import autoLauncher from '../services/autoLauncher';
|
||||
import { isPlatform } from './main';
|
||||
import { isPlatform } from './common/platform';
|
||||
import ElectronLog from 'electron-log';
|
||||
|
||||
export function buildContextMenu(
|
||||
|
|
2
ui
2
ui
|
@ -1 +1 @@
|
|||
Subproject commit 3a37be3e4f4c6372a6ffd1ec53b588e6a93649f0
|
||||
Subproject commit 197b5f35f3588e142558636ccc1854f44b725861
|
Loading…
Reference in a new issue