From 240c9d7e89b432251f76f2cb82cc13866e995a61 Mon Sep 17 00:00:00 2001 From: an-lee Date: Fri, 1 Mar 2024 10:02:00 +0800 Subject: [PATCH] config asar when package --- enjoy/forge.config.js | 10 +++++++++- enjoy/src/main/ffmpeg.ts | 15 ++++++++++----- enjoy/src/main/whisper.ts | 9 +++++++-- enjoy/tsconfig.json | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/enjoy/forge.config.js b/enjoy/forge.config.js index 243b4dea..36824bc3 100644 --- a/enjoy/forge.config.js +++ b/enjoy/forge.config.js @@ -9,7 +9,11 @@ import os from "os"; const config = { packagerConfig: { - asar: false, + asar: { + // Binary files won't work in asar, so we need to unpack them + unpackDir: + "{.vite/build/lib,.vite/build/samples,node_modules/ffmpeg-static,node_modules/@andrkrn/ffprobe-static}", + }, icon: "./assets/icon", name: "Enjoy", executableName: "enjoy", @@ -79,6 +83,10 @@ const config = { }, ], }), + { + name: "@electron-forge/plugin-auto-unpack-natives", + config: {}, + }, // Fuses are used to enable/disable various Electron functionality // at package time, before code signing the application // new FusesPlugin({ diff --git a/enjoy/src/main/ffmpeg.ts b/enjoy/src/main/ffmpeg.ts index 8a8105cd..22a04ba3 100644 --- a/enjoy/src/main/ffmpeg.ts +++ b/enjoy/src/main/ffmpeg.ts @@ -6,13 +6,18 @@ import log from "@main/logger"; import path from "path"; import fs from "fs-extra"; import settings from "./settings"; -import url from 'url'; +import url from "url"; +/* + * ffmpeg and ffprobe bin file will be in /app.asar.unpacked instead of /app.asar + * the /samples folder is also in /app.asar.unpacked + */ +Ffmpeg.setFfmpegPath(ffmpegPath.replace("app.asar", "app.asar.unpacked")); +Ffmpeg.setFfprobePath(ffprobePath.replace("app.asar", "app.asar.unpacked")); const __filename = url.fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); - -Ffmpeg.setFfmpegPath(ffmpegPath); -Ffmpeg.setFfprobePath(ffprobePath); +const __dirname = path + .dirname(__filename) + .replace("app.asar", "app.asar.unpacked"); const logger = log.scope("ffmpeg"); export default class FfmpegWrapper { diff --git a/enjoy/src/main/whisper.ts b/enjoy/src/main/whisper.ts index 10b4bc87..90145734 100644 --- a/enjoy/src/main/whisper.ts +++ b/enjoy/src/main/whisper.ts @@ -5,10 +5,15 @@ import { WHISPER_MODELS_OPTIONS, PROCESS_TIMEOUT } from "@/constants"; import { exec, spawn } from "child_process"; import fs from "fs-extra"; import log from "@main/logger"; -import url from 'url'; +import url from "url"; const __filename = url.fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +/* + * whipser bin file will be in /app.asar.unpacked instead of /app.asar + */ +const __dirname = path + .dirname(__filename) + .replace("app.asar", "app.asar.unpacked"); const logger = log.scope("whisper"); diff --git a/enjoy/tsconfig.json b/enjoy/tsconfig.json index 96e6d21b..138d3867 100644 --- a/enjoy/tsconfig.json +++ b/enjoy/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "ESNext", - "module": "commonjs", + "module": "ESNext", "allowJs": true, "skipLibCheck": true, "esModuleInterop": true,