diff --git a/build/image-magick b/build/image-magick new file mode 100755 index 000000000..d5d5062e2 Binary files /dev/null and b/build/image-magick differ diff --git a/package.json b/package.json index 02b535e47..109fc16bb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ente", "productName": "ente", - "version": "1.6.14", + "version": "1.6.15-beta.1", "private": true, "description": "Desktop client for ente.io", "main": "app/main.js", diff --git a/src/api/heicConvert.ts b/src/api/heicConvert.ts index 03179edf1..68909b678 100644 --- a/src/api/heicConvert.ts +++ b/src/api/heicConvert.ts @@ -1,10 +1,6 @@ import { ipcRenderer } from 'electron/renderer'; -import { isPlatformMac } from '../utils/preload'; export async function convertHEIC(fileData: Uint8Array): Promise { - if (!isPlatformMac()) { - throw Error('native heic conversion only supported on mac'); - } const convertedFileData = await ipcRenderer.invoke( 'convert-heic', fileData diff --git a/src/services/appUpdater.ts b/src/services/appUpdater.ts index 7200c91f1..533b24fef 100644 --- a/src/services/appUpdater.ts +++ b/src/services/appUpdater.ts @@ -6,9 +6,9 @@ import semVerCmp from 'semver-compare'; import { AppUpdateInfo, GetFeatureFlagResponse } from '../types'; import { getSkipAppVersion, setSkipAppVersion } from './userPreference'; import fetch from 'node-fetch'; -import { isPlatformMac } from '../utils/main'; import { logErrorSentry } from './sentry'; import ElectronLog from 'electron-log'; +import { isPlatform } from '../utils/main'; const FIVE_MIN_IN_MICROSECOND = 5 * 60 * 1000; @@ -43,7 +43,7 @@ export async function checkForUpdateAndNotify(mainWindow: BrowserWindow) { const desktopCutoffVersion = await getDesktopCutoffVersion(); if ( desktopCutoffVersion && - isPlatformMac() && + isPlatform('mac') && semVerCmp( updateCheckResult.updateInfo.version, desktopCutoffVersion diff --git a/src/services/autoLauncher.ts b/src/services/autoLauncher.ts index 80111ea46..c28eb177c 100644 --- a/src/services/autoLauncher.ts +++ b/src/services/autoLauncher.ts @@ -1,12 +1,12 @@ +import { isPlatform } from '../utils/main'; import { AutoLauncherClient } from '../types/autoLauncher'; -import { isPlatformWindows, isPlatformMac } from '../utils/main'; import linuxAutoLauncher from './autoLauncherClients/linuxAutoLauncher'; import macAndWindowsAutoLauncher from './autoLauncherClients/macAndWindowsAutoLauncher'; class AutoLauncher { private client: AutoLauncherClient; init() { - if (isPlatformMac() || isPlatformWindows()) { + if (isPlatform('mac') || isPlatform('windows')) { this.client = macAndWindowsAutoLauncher; } else { this.client = linuxAutoLauncher; diff --git a/src/services/heicConvertor.ts b/src/services/heicConverter.ts similarity index 64% rename from src/services/heicConvertor.ts rename to src/services/heicConverter.ts index cb90bbba3..c094cde06 100644 --- a/src/services/heicConvertor.ts +++ b/src/services/heicConverter.ts @@ -5,9 +5,18 @@ import { rmSync } from 'fs'; import { readFile, writeFile } from 'promise-fs'; import { generateTempFilePath } from '../utils/temp'; import { logErrorSentry } from './sentry'; +import { isPlatform } from '../utils/main'; +import { isDev } from '../utils/common'; +import path from 'path'; const asyncExec = util.promisify(exec); +function getImageMagickStaticPath() { + return isDev + ? 'build/image-magick' + : path.join(process.resourcesPath, 'image-magick'); +} + export async function convertHEIC( heicFileData: Uint8Array ): Promise { @@ -19,9 +28,8 @@ export async function convertHEIC( await writeFile(tempInputFilePath, heicFileData); - await asyncExec( - `sips -s format jpeg ${tempInputFilePath} --out ${tempOutputFilePath}` - ); + await runConvertCommand(tempInputFilePath, tempOutputFilePath); + const convertedFileData = new Uint8Array( await readFile(tempOutputFilePath) ); @@ -42,3 +50,20 @@ export async function convertHEIC( } } } + +async function runConvertCommand( + tempInputFilePath: string, + tempOutputFilePath: string +) { + if (isPlatform('mac')) { + await asyncExec( + `sips -s format jpeg ${tempInputFilePath} --out ${tempOutputFilePath}` + ); + } else if (isPlatform('linux')) { + await asyncExec( + `${getImageMagickStaticPath()} ${tempInputFilePath} -quality 100% ${tempOutputFilePath}` + ); + } else { + Error(`${process.platform} native heic convert not supported yet`); + } +} diff --git a/src/utils/createWindow.ts b/src/utils/createWindow.ts index 415b2f232..db356d467 100644 --- a/src/utils/createWindow.ts +++ b/src/utils/createWindow.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { isDev } from './common'; import { isAppQuitting } from '../main'; import { PROD_HOST_URL } from '../config'; -import { isPlatformMac } from './main'; +import { isPlatform } from './main'; import { getHideDockIconPreference } from '../services/userPreference'; import autoLauncher from '../services/autoLauncher'; @@ -83,12 +83,12 @@ export async function createWindow(): Promise { }); mainWindow.on('hide', () => { const shouldHideDockIcon = getHideDockIconPreference(); - if (isPlatformMac() && shouldHideDockIcon) { + if (isPlatform('mac') && shouldHideDockIcon) { app.dock.hide(); } }); mainWindow.on('show', () => { - if (isPlatformMac()) { + if (isPlatform('mac')) { app.dock.show(); } }); diff --git a/src/utils/ipcComms.ts b/src/utils/ipcComms.ts index daa92f6c2..debec6273 100644 --- a/src/utils/ipcComms.ts +++ b/src/utils/ipcComms.ts @@ -14,7 +14,7 @@ import { getSentryUserID, logErrorSentry } from '../services/sentry'; import chokidar from 'chokidar'; import path from 'path'; import { getDirFilePaths } from '../services/fs'; -import { convertHEIC } from '../services/heicConvertor'; +import { convertHEIC } from '../services/heicConverter'; import { getAppVersion, skipAppVersion, diff --git a/src/utils/main.ts b/src/utils/main.ts index b0c211be6..383f61c39 100644 --- a/src/utils/main.ts +++ b/src/utils/main.ts @@ -88,19 +88,23 @@ export function setupNextElectronServe() { }); } -export function isPlatformMac() { - return process.platform === 'darwin'; -} - -export function isPlatformWindows() { - return process.platform === 'win32'; +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(); - if (isPlatformMac() && shouldHideDockIcon && wasAutoLaunched) { + if (isPlatform('mac') && shouldHideDockIcon && wasAutoLaunched) { app.dock.hide(); } } diff --git a/src/utils/menu.ts b/src/utils/menu.ts index 0d46bb649..5002a1205 100644 --- a/src/utils/menu.ts +++ b/src/utils/menu.ts @@ -11,7 +11,7 @@ import { } from '../services/userPreference'; import { setIsAppQuitting } from '../main'; import autoLauncher from '../services/autoLauncher'; -import { isPlatformMac } from './main'; +import { isPlatform } from './main'; import ElectronLog from 'electron-log'; export function buildContextMenu( @@ -88,7 +88,7 @@ export function buildContextMenu( export async function buildMenuBar(): Promise { let isAutoLaunchEnabled = await autoLauncher.isEnabled(); - const isMac = isPlatformMac(); + const isMac = isPlatform('mac'); let shouldHideDockIcon = getHideDockIconPreference(); const template: MenuItemConstructorOptions[] = [ { diff --git a/src/utils/preload.ts b/src/utils/preload.ts index 1da5bd833..f29a1d543 100644 --- a/src/utils/preload.ts +++ b/src/utils/preload.ts @@ -14,11 +14,3 @@ export const fixHotReloadNext12 = () => { }) });`); }; - -export function isPlatformMac() { - return process.platform === 'darwin'; -} - -export function isPlatformWindows() { - return process.platform === 'win32'; -}