From 034b362d0623cac845b07221997dcf45c2438925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ACT=E4=B8=B6=E6=B5=81=E6=98=9F=E9=9B=A8?= <1340145680@qq.com> Date: Tue, 10 Feb 2026 21:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BD=E5=B1=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron-builder.yml | 1 + scripts/main.ts | 6 +++++- src/env.ts | 21 ++++++++++++++++++--- src/lib/fixDB.ts | 2 +- src/types/database.d.ts | 10 ++++------ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/electron-builder.yml b/electron-builder.yml index 40b752b..0ebf062 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -18,6 +18,7 @@ files: - "!**/*.d.ts" - "!src/**/*" - "!scripts/**/*.ts" + - "!scripts/*.ts" asar: true diff --git a/scripts/main.ts b/scripts/main.ts index ff09072..a97fb0e 100644 --- a/scripts/main.ts +++ b/scripts/main.ts @@ -18,7 +18,11 @@ function createMainWindow(): void { } app.whenReady().then(async () => { createMainWindow(); - await startServe(); + try { + await startServe(); + } catch (err) { + console.error("[服务启动失败]:", err); + } }); app.on("window-all-closed", () => { diff --git a/src/env.ts b/src/env.ts index 069a4ee..5b209d5 100644 --- a/src/env.ts +++ b/src/env.ts @@ -7,13 +7,28 @@ const defaultEnvValues: Record = { prod: `NODE_ENV=prod\nPORT=60000\nOSSURL=http://127.0.0.1:60000/`, }; -//加载环境变量 -const env = process.env.NODE_ENV ?? "dev"; +// 判断是否为打包后的 Electron 环境 +const isElectron = typeof process.versions?.electron !== "undefined"; +let isPackaged = false; +if (isElectron) { + const { app } = require("electron"); + isPackaged = app.isPackaged; +} + +//加载环境变量(打包环境默认使用 prod) +const env = process.env.NODE_ENV ?? (isPackaged ? "prod" : "dev"); if (!env) { console.log("[环境变量为空]"); process.exit(1); } else { - const envDir = path.resolve("env"); + // Electron 打包环境使用 userData 目录,开发环境使用项目根目录 + let envDir: string; + if (isElectron) { + const { app } = require("electron"); + envDir = path.join(app.getPath("userData"), "env"); + } else { + envDir = path.resolve("env"); + } const envFilePath = path.join(envDir, `.env.${env}`); // 自动创建 env 目录和文件(.gitignore 可能忽略了这些文件) diff --git a/src/lib/fixDB.ts b/src/lib/fixDB.ts index 79df5e8..9c52bcd 100644 --- a/src/lib/fixDB.ts +++ b/src/lib/fixDB.ts @@ -29,7 +29,7 @@ export default async (knex: Knex): Promise => { await addColumn("t_video", "aiConfigId", "integer"); await addColumn("t_config", "modelType", "text"); await addColumn("t_videoConfig", "audioEnabled", "integer"); - await addColumn("t_videoConfig", "errorReason", "text"); + await addColumn("t_video", "errorReason", "text"); //更正字段 await alterColumnType("t_config", "modelType", "text"); diff --git a/src/types/database.d.ts b/src/types/database.d.ts index 67c3c9c..c90deda 100644 --- a/src/types/database.d.ts +++ b/src/types/database.d.ts @@ -1,8 +1,7 @@ -// @db-hash 5a1cbe86324cb073c1931fc53c56725f +// @db-hash 5a633f2d45df5d971905dd32c0ac9880 //该文件由脚本自动生成,请勿手动修改 -export interface _t_video_old_20260210 { - 'aiConfigId'?: number | null; +export interface _t_video_old_20260131 { 'configId'?: number | null; 'filePath'?: string | null; 'firstFrame'?: string | null; @@ -53,6 +52,7 @@ export interface t_config { 'manufacturer'?: string | null; 'model'?: string | null; 'modelType'?: string | null; + 'name'?: string | null; 'type'?: string | null; 'userId'?: number | null; } @@ -139,7 +139,6 @@ export interface t_user { export interface t_video { 'aiConfigId'?: number | null; 'configId'?: number | null; - 'errorReason'?: string | null; 'filePath'?: string | null; 'firstFrame'?: string | null; 'id'?: number; @@ -152,7 +151,6 @@ export interface t_video { 'time'?: number | null; } export interface t_videoConfig { - 'aiConfigId'?: number | null; 'audioEnabled'?: number | null; 'createTime'?: number | null; 'duration'?: number | null; @@ -172,7 +170,7 @@ export interface t_videoConfig { } export interface DB { - "_t_video_old_20260210": _t_video_old_20260210; + "_t_video_old_20260131": _t_video_old_20260131; "t_aiModelMap": t_aiModelMap; "t_assets": t_assets; "t_chatHistory": t_chatHistory;