Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,49 @@ function ffmpegDownloadPlugin() {
// 只在生产构建时下载 FFmpeg
if (!isProd) return

console.log('Downloading FFmpeg...')
// 根据构建目标决定下载哪个平台
const targetPlatform = process.env.BUILD_TARGET_PLATFORM || process.platform
const targetArch = process.env.BUILD_TARGET_ARCH || process.arch

// 检查是否已存在,避免重复下载
const ffmpegPath = path.resolve(
'resources/ffmpeg',
`${targetPlatform}-${targetArch}`,
targetPlatform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg'
)

if (fs.existsSync(ffmpegPath)) {
console.log(`FFmpeg already exists for ${targetPlatform}-${targetArch}`)
return
}
Comment on lines +21 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use a logger instead of console; early-exit check is good.

Replace console with a build-time logger to meet logging rules. Keep the path computation unchanged.

-      if (fs.existsSync(ffmpegPath)) {
-        console.log(`FFmpeg already exists for ${targetPlatform}-${targetArch}`)
+      if (fs.existsSync(ffmpegPath)) {
+        logger.info('FFmpeg already exists', { platform: targetPlatform, arch: targetArch })
         return
       }

Add at top:

+import logger from './scripts/build-logger'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 根据构建目标决定下载哪个平台
const targetPlatform = process.env.BUILD_TARGET_PLATFORM || process.platform
const targetArch = process.env.BUILD_TARGET_ARCH || process.arch
// 检查是否已存在,避免重复下载
const ffmpegPath = path.resolve(
'resources/ffmpeg',
`${targetPlatform}-${targetArch}`,
targetPlatform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg'
)
if (fs.existsSync(ffmpegPath)) {
console.log(`FFmpeg already exists for ${targetPlatform}-${targetArch}`)
return
}
import logger from './scripts/build-logger'
// 根据构建目标决定下载哪个平台
const targetPlatform = process.env.BUILD_TARGET_PLATFORM || process.platform
const targetArch = process.env.BUILD_TARGET_ARCH || process.arch
// 检查是否已存在,避免重复下载
const ffmpegPath = path.resolve(
'resources/ffmpeg',
`${targetPlatform}-${targetArch}`,
targetPlatform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg'
)
if (fs.existsSync(ffmpegPath)) {
logger.info('FFmpeg already exists', { platform: targetPlatform, arch: targetArch })
return
}
🤖 Prompt for AI Agents
In electron.vite.config.ts around lines 21 to 35, replace the console.log call
with your project's build-time logger: add an import/require for the build
logger at the top of the file (for example import { buildLogger } from
'<project-build-logger-path>') and change console.log(`FFmpeg already exists for
${targetPlatform}-${targetArch}`) to buildLogger.info(`FFmpeg already exists for
${targetPlatform}-${targetArch}`); keep the ffmpegPath computation and the
fs.existsSync early-exit logic unchanged.


try {
// 根据构建目标决定下载哪个平台
const targetPlatform = process.env.BUILD_TARGET_PLATFORM || process.platform
const targetArch = process.env.BUILD_TARGET_ARCH || process.arch
console.log(`Downloading FFmpeg for ${targetPlatform}-${targetArch}...`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Prefer logger for status messages.

-      console.log(`Downloading FFmpeg for ${targetPlatform}-${targetArch}...`)
+      logger.info('Downloading FFmpeg', { platform: targetPlatform, arch: targetArch })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log(`Downloading FFmpeg for ${targetPlatform}-${targetArch}...`)
logger.info('Downloading FFmpeg', { platform: targetPlatform, arch: targetArch })
🤖 Prompt for AI Agents
In electron.vite.config.ts around line 37, replace the console.log status
message with the project's structured logger; use the existing logger instance
(e.g., logger.info or logger.debug) or import the shared logger module and call
it with the same message `Downloading FFmpeg for
${targetPlatform}-${targetArch}...`; ensure you remove the console.log call and
use the logger so messages follow the application's logging configuration and
formatting.


try {
await new Promise<void>((resolve, reject) => {
const downloadScript = spawn(
'tsx',
['scripts/download-ffmpeg.ts', 'platform', targetPlatform, targetArch],
{
stdio: 'inherit'
// 在不同环境中使用不同的命令来确保兼容性
let command: string
let args: string[]

if (process.platform === 'win32') {
// Windows 环境:使用 npm run 调用脚本,更可靠
command = 'npm'
args = ['run', 'ffmpeg:download']
} else {
// Unix 环境:直接使用 tsx
command = 'tsx'
args = ['scripts/download-ffmpeg.ts', 'platform', targetPlatform, targetArch]
}

const downloadScript = spawn(command, args, {
stdio: 'inherit',
shell: process.platform === 'win32',
env: {
...process.env,
BUILD_TARGET_PLATFORM: targetPlatform,
BUILD_TARGET_ARCH: targetArch
}
)
})

downloadScript.on('close', (code) => {
if (code === 0) {
Expand All @@ -48,7 +76,8 @@ function ffmpegDownloadPlugin() {
})
})
} catch (error) {
console.warn('FFmpeg Download failed', error)
console.error('FFmpeg Download failed:', error)
throw new Error(`Failed to download FFmpeg for ${targetPlatform}-${targetArch}: ${error}`)
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
"start": "electron-vite preview",
"dev": "electron-vite dev",
"build": "npm run typecheck && electron-vite build",
"build:release": "npm run typecheck && electron-vite build",
"postinstall": "electron-builder install-app-deps",
"build:unpack": "npm run build && electron-builder --dir --publish never",
"build:win": "npm run build && electron-builder --win --publish never",
"build:win:x64": "npm run build && electron-builder --win --x64 --publish never",
"build:win:arm64": "npm run build && electron-builder --win --arm64 --publish never",
"build:win": "cross-env BUILD_TARGET_PLATFORM=win32 npm run build && electron-builder --win --publish never",
"build:win:x64": "cross-env BUILD_TARGET_PLATFORM=win32 BUILD_TARGET_ARCH=x64 npm run build && electron-builder --win --x64 --publish never",
"build:win:arm64": "cross-env BUILD_TARGET_PLATFORM=win32 BUILD_TARGET_ARCH=arm64 npm run build && electron-builder --win --arm64 --publish never",
"build:mac": "electron-vite build && electron-builder --mac --publish never",
"build:mac:x64": "npm run build && electron-builder --mac --x64 --publish never",
"build:mac:arm64": "npm run build && electron-builder --mac --arm64 --publish never",
Expand All @@ -47,10 +48,10 @@
"version:prerelease": "tsx scripts/version-manager.ts prerelease",
"version:beta": "tsx scripts/version-manager.ts minor beta",
"version:beta-patch": "tsx scripts/version-manager.ts patch beta",
"release": "npm run build && electron-builder --publish onTagOrDraft",
"release:all": "npm run build && electron-builder --publish always",
"release:never": "npm run build && electron-builder --publish never",
"release:draft": "npm run build && electron-builder --publish onTagOrDraft",
"release": "npm run ffmpeg:download-all && npm run build:release && electron-builder --publish onTagOrDraft",
"release:all": "npm run ffmpeg:download-all && npm run build:release && electron-builder --publish always",
"release:never": "npm run ffmpeg:download-all && npm run build:release && electron-builder --publish never",
"release:draft": "npm run ffmpeg:download-all && npm run build:release && electron-builder --publish onTagOrDraft",
"migrate": "tsx src/main/db/migration-cli.ts",
"migrate:up": "npm run migrate up",
"migrate:down": "npm run migrate down",
Expand All @@ -71,7 +72,8 @@
"ffmpeg:download-all": "tsx scripts/download-ffmpeg.ts all",
"ffmpeg:clean": "tsx scripts/download-ffmpeg.ts clean",
"ffmpeg:test": "tsx scripts/test-ffmpeg-integration.ts",
"prebuild": "npm run ffmpeg:download"
"prebuild": "npm run ffmpeg:download",
"prebuild:release": "echo 'FFmpeg already downloaded by release script'"
},
"dependencies": {
"@ant-design/icons": "^6.0.1",
Expand Down Expand Up @@ -128,6 +130,7 @@
"@welldone-software/why-did-you-render": "^10.0.1",
"cli-progress": "^3.12.0",
"code-inspector-plugin": "^1.2.7",
"cross-env": "^10.0.0",
"electron": "37.2.4",
"electron-builder": "26.0.19",
"electron-devtools-installer": "^4.0.0",
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion scripts/download-ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,28 @@ class FFmpegDownloader {
// CLI 入口
async function main() {
const args = process.argv.slice(2)
const command = args[0] || 'current'
let command = args[0]

const downloader = new FFmpegDownloader()

try {
// 优先检查环境变量,如果设置了构建目标则使用目标平台
if (process.env.BUILD_TARGET_PLATFORM) {
console.log(
`检测到构建目标平台: ${process.env.BUILD_TARGET_PLATFORM}-${process.env.BUILD_TARGET_ARCH || process.arch}`
)
await downloader.downloadFFmpeg(
process.env.BUILD_TARGET_PLATFORM,
process.env.BUILD_TARGET_ARCH || process.arch
)
return
}

// 如果没有环境变量,按原逻辑处理命令参数
if (!command) {
command = 'current'
}

switch (command) {
case 'all':
await downloader.downloadAllPlatforms()
Expand Down Expand Up @@ -416,6 +433,10 @@ async function main() {
win32: x64, arm64
darwin: x64, arm64
linux: x64, arm64

环境变量:
BUILD_TARGET_PLATFORM - 构建目标平台 (win32, darwin, linux)
BUILD_TARGET_ARCH - 构建目标架构 (x64, arm64)
`)
}
} catch (error) {
Expand Down
Loading