浏览代码

Merge pull request #113 from ente-io/image-magick-static

Image magick static
Abhinav Kumar 2 年之前
父节点
当前提交
f5ee5eca27

二进制
build/image-magick


+ 1 - 1
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",

+ 0 - 4
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<Uint8Array> {
-    if (!isPlatformMac()) {
-        throw Error('native heic conversion only supported on mac');
-    }
     const convertedFileData = await ipcRenderer.invoke(
         'convert-heic',
         fileData

+ 2 - 2
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

+ 2 - 2
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;

+ 28 - 3
src/services/heicConvertor.ts → 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<Uint8Array> {
@@ -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`);
+    }
+}

+ 3 - 3
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<BrowserWindow> {
     });
     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();
         }
     });

+ 1 - 1
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,

+ 11 - 7
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();
     }
 }

+ 2 - 2
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<Menu> {
     let isAutoLaunchEnabled = await autoLauncher.isEnabled();
-    const isMac = isPlatformMac();
+    const isMac = isPlatform('mac');
     let shouldHideDockIcon = getHideDockIconPreference();
     const template: MenuItemConstructorOptions[] = [
         {

+ 0 - 8
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';
-}