Skip to content

Commit a7fc272

Browse files
committedSep 10, 2024·
feat: 打包后无法现在,以及重新调整log日志
1 parent a1e4a1c commit a7fc272

File tree

7 files changed

+162
-108
lines changed

7 files changed

+162
-108
lines changed
 

‎command/database.sqlite3

12 KB
Binary file not shown.

‎electron/main.ts

+66-43
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
11
import path from "path";
22
import { exec, execSync } from "child_process";
3+
import electronLog from 'electron-log';
34
import fs from "fs-extra";
45
import { app, BrowserWindow, ipcMain } from "electron";
56
import { format } from "date-fns";
67
import { getHtml ,getAuthCmd, getExecuteFile, getExecutePath } from "./utils";
78
import { connectDataBase, findRecord, insertRecord } from "./sqlHelper";
89
import sharp from 'sharp'
910
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
10-
let templateFilePath = path.join(process.cwd(), "resources", "command");
11-
12-
13-
if (import.meta.env.DEV) {
14-
templateFilePath = path.join(process.cwd(), "command");
15-
}
16-
console.log(templateFilePath, "templateFilePath");
17-
18-
const ytDlp = path.join(
19-
process.cwd(),
20-
"command",
21-
getExecutePath(),
22-
getExecuteFile("yt-dlp")
23-
);
24-
25-
const ytDlpPath = `${getAuthCmd()} ${ytDlp}`;
26-
27-
const ffmpeg = path.join(
28-
process.cwd(),
29-
"command",
30-
getExecutePath(),
31-
getExecuteFile("ffmpeg")
32-
);
33-
34-
const ffmpegPath = `${getAuthCmd()} ${ffmpeg}`;
35-
36-
const removeDuplicateImages = path.join(
37-
process.cwd(),
38-
"command",
39-
getExecutePath(),
40-
getExecuteFile("RemoveDuplicateImages")
41-
);
42-
43-
const removeDuplicateImagesPath = `${getAuthCmd()} ${removeDuplicateImages}`;
4411

4512
// The built directory structure
4613
//
@@ -107,8 +74,55 @@ function createWindow() {
10774
// win.loadFile('dist/index.html')
10875
win.loadFile(path.join(process.env.DIST, "index.html"));
10976
}
77+
78+
// 重写console.log方法
79+
const originalConsoleLog = console.log;
80+
console.log = (...args) => {
81+
originalConsoleLog(...args);
82+
win?.webContents.send('main-process-log', args);
83+
};
84+
85+
// 重写electron-log的日志方法
86+
['error', 'warn', 'info', 'verbose', 'debug', 'silly'].forEach(level => {
87+
const originalLog = electronLog[level];
88+
electronLog[level] = (...args) => {
89+
originalLog(...args);
90+
win?.webContents.send('main-process-log', [level, ...args]);
91+
};
92+
});
11093
}
11194

95+
let templateFilePath = path.join(process.cwd(), "resources", "command");
96+
97+
if (!import.meta.env.PROD) {
98+
templateFilePath = path.join(process.cwd(), "command");
99+
}
100+
console.log(templateFilePath, "templateFilePath");
101+
102+
const ytDlp = path.join(
103+
templateFilePath,
104+
getExecutePath(),
105+
getExecuteFile("yt-dlp")
106+
);
107+
108+
const ytDlpPath = `${getAuthCmd()} ${ytDlp}`;
109+
110+
const ffmpeg = path.join(
111+
templateFilePath,
112+
getExecutePath(),
113+
getExecuteFile("ffmpeg")
114+
);
115+
116+
const ffmpegPath = `${getAuthCmd()} ${ffmpeg}`;
117+
118+
const removeDuplicateImages = path.join(
119+
templateFilePath,
120+
getExecutePath(),
121+
getExecuteFile("RemoveDuplicateImages")
122+
);
123+
124+
const removeDuplicateImagesPath = `${getAuthCmd()} ${removeDuplicateImages}`;
125+
112126
app.on("window-all-closed", () => {
113127
app.quit();
114128
win = null;
@@ -120,8 +134,7 @@ ipcMain.on("call-yt-dlp-video", async(event,videoUrl: string) => {
120134
let record: any = await findRecord(videoUrl);
121135
console.log(record, "record-------------------")
122136
let locationPath = path.join(
123-
process.cwd(),
124-
"command",
137+
templateFilePath,
125138
record.FolderDate
126139
);
127140

@@ -176,8 +189,7 @@ ipcMain.on("call-yt-dlp", async (event, videoUrl, isDownloadVideo) => {
176189
const createInfo = createMetadata(videoUrl);
177190

178191
let locationPath = path.join(
179-
process.cwd(),
180-
"command",
192+
templateFilePath,
181193
createInfo.folderDate
182194
);
183195

@@ -268,8 +280,7 @@ ipcMain.on(
268280
const startTimeName = everyStartTime.replace(/[.:,-]/g, "");
269281
console.log(startTimeName, "startTimeName")
270282
const imagePath = path.join(
271-
process.cwd(),
272-
"command",
283+
templateFilePath,
273284
folderDate,
274285
startTimeName
275286
);
@@ -309,13 +320,17 @@ ipcMain.on("call-get-duration", (event, folderDate) => {
309320
event.reply("reply-duration", packageJson.duration);
310321
})
311322

323+
ipcMain.on("call-execute-path", (event)=> {
324+
event.reply("reply-execute-path", process.cwd());
325+
})
326+
312327
/**
313328
* 图片压缩
314329
*/
315330
ipcMain.on("call-image-compress", (event, folderDate, everyStartTime, list) => {
316331
console.log("call-image-compress", list)
317332
const startTimeName = everyStartTime.replace(/[.:,-]/g, "");
318-
const locationPath = path.join(process.cwd(),"command", folderDate, startTimeName);
333+
const locationPath = path.join(templateFilePath, folderDate, startTimeName);
319334
list.forEach(async(item: any, index: number) => {
320335
console.log(item, "fileName")
321336
let fileName = item.split('.')[0];
@@ -382,6 +397,7 @@ const removeSimilarImages = (imagePath: string, multiple: number) => {
382397
/**
383398
* 在指定目录下查找元数据json文件
384399
* @param directoryPath
400+
* @param type
385401
* @returns
386402
*/
387403
const findJsonFilesInDirectorySync = (
@@ -425,12 +441,19 @@ const createMetadata = (url: string) => {
425441
const folderDate = format(new Date(), "yyyy-MM-dd-HH-mm-ss");
426442
console.log(folderDate, "date-folderDate");
427443

428-
const locationPath = path.join(process.cwd(),"command", folderDate);
444+
const locationPath = path.join(templateFilePath, folderDate);
429445
let cmd = "";
430446
cmd = ` ${ytDlpPath} ${url} -P ${locationPath} --write-info-json --skip-download -o "%(id)s.%(ext)s"`;
431447

432448
console.log(cmd, "cmd-123");
433-
execSync(cmd);
449+
try
450+
{
451+
execSync(cmd);
452+
}
453+
catch (e) {
454+
console.log("执行cmd-123失败", e);
455+
}
456+
console.log("cmd-123执行完毕");
434457
const jsonFile: string | undefined =
435458
findJsonFilesInDirectorySync(locationPath);
436459

‎package-lock.json

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-vite-vue3-tools",
3-
"version": "0.0.33",
3+
"version": "0.0.35",
44
"main": "dist-electron/main.js",
55
"author": "aehyok",
66
"license": "MIT",
@@ -9,12 +9,12 @@
99
"scripts": {
1010
"postinstall": "electron-builder install-app-deps",
1111
"start-win": "chcp 65001 && vite",
12-
"build-win": "chcp 65001 && vite build && electron-builder",
12+
"build-win": "chcp 65001 && vite build --mode production && electron-builder",
1313
"start-mac": "vite",
1414
"python-win": "cd python/RemoveDuplicateImages && pyinstaller --onefile main.py -y --distpath ../../command/win -n RemoveDuplicateImages.exe",
1515
"python-whisper": "cd python/Whisper && pyinstaller --hidden-import=openai-whisper --onefile main.py -y --distpath ../../command/win -n Whisper.exe",
1616
"python-mac": "cd python/RemoveDuplicateImages && pyinstaller --onefile main.py -y --distpath ../../command/mac -n RemoveDuplicateImages",
17-
"build": "vite build && electron-builder"
17+
"build": "vite build --mode production && electron-builder"
1818
},
1919
"dependencies": {
2020
"@google/generative-ai": "^0.1.3",
@@ -23,6 +23,7 @@
2323
"@vicons/ionicons5": "^0.12.0",
2424
"cheerio": "^1.0.0-rc.12",
2525
"date-fns": "^2.30.0",
26+
"electron-log": "^5.2.0",
2627
"fs-extra": "^11.2.0",
2728
"lucide-vue-next": "^0.395.0",
2829
"md-editor-v3": "^4.13.3",

‎src/main.ts

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ ipcRenderer.invoke("local-sqlite3-db").then(async (dbPath) => {
1717
console.log(dbPath, "渲染进程获取到数据库路径");
1818
});
1919

20+
ipcRenderer.on('main-process-log', (event, args) => {
21+
console.log('electron主进程日志:', ...args);
22+
});
23+
2024
// Remove Preload scripts loading
2125
const app = createApp(App);
2226
app.use(router);

‎src/views/home/index.vue

+44-45
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616
type="primary"
1717
style="margin-left: 10px; margin-right: 10px;"
1818
>保存</n-button
19-
></div>
19+
>
20+
<n-button
21+
@click="setClick"
22+
size="small"
23+
type="info"
24+
style="margin-left: 10px; margin-right: 10px;"
25+
>设置</n-button
26+
>
27+
28+
</div>
2029
</n-layout-header>
2130
<n-layout has-sider content-style="padding: 24px;">
2231
<n-layout-content content-style="margin-left:20px;">
@@ -64,17 +73,7 @@
6473

6574
<n-drawer v-model:show="active" :width="502" :placement="'right'">
6675
<n-drawer-content title="系统设置">
67-
<n-collapse>
68-
<n-collapse-item title="文件下载地址" name="1">
69-
<div>文件下载地址</div>
70-
</n-collapse-item>
71-
<n-collapse-item title="Google Gemini" name="2">
72-
<div>Gemini Api</div>
73-
</n-collapse-item>
74-
<n-collapse-item title="OpenAI ChatGPT" name="3">
75-
<div>ChatGPT Api</div>
76-
</n-collapse-item>
77-
</n-collapse>
76+
7877
</n-drawer-content>
7978
</n-drawer>
8079

@@ -599,39 +598,39 @@ onMounted( async() => {
599598
});
600599
601600
// 点击获取字幕
602-
const subtitleClick = async () => {
603-
console.log("rrrrrr-engligsh")
604-
605-
console.log(input.value.indexOf("toutiao"), "dddddddd")
606-
//先检查一下url是否为空
607-
console.log(input.value, "inputValue");
608-
if (input.value === "" || input.value === null) {
609-
message.warning("请输入视频链接");
610-
return;
611-
}
612-
613-
const row: any = await get(
614-
`select * from ParsingVideo where Path = ? and Env = ? `,
615-
[input.value, import.meta.env.MODE]
616-
);
617-
618-
console.log(row, "row===row==input");
619-
if (row && row.Id) {
620-
console.log(row, "row-input", row.FolderDate);
621-
outputSource.value = row.SourceSubtitles;
622-
outputTarget.value = row.TargetSubtitles;
623-
624-
state.currentVideoData = row;
625-
selectedKey.value = row.Id;
626-
message.success("此链接视频已被下载,已跳转到该视频");
627-
} else {
628-
showPin.value = true;
629-
state.loadingText = "正在下载请稍后...";
630-
631-
console.log("准备下载");
632-
ipcRenderer.send("call-yt-dlp", input.value, checkedValue.value);
633-
}
634-
};
601+
// const subtitleClick = async () => {
602+
// console.log("rrrrrr-engligsh")
603+
//
604+
// console.log(input.value.indexOf("toutiao"), "dddddddd")
605+
// //先检查一下url是否为空
606+
// console.log(input.value, "inputValue");
607+
// if (input.value === "" || input.value === null) {
608+
// message.warning("请输入视频链接");
609+
// return;
610+
// }
611+
//
612+
// const row: any = await get(
613+
// `select * from ParsingVideo where Path = ? and Env = ? `,
614+
// [input.value, import.meta.env.MODE]
615+
// );
616+
//
617+
// console.log(row, "row===row==input");
618+
// if (row && row.Id) {
619+
// console.log(row, "row-input", row.FolderDate);
620+
// outputSource.value = row.SourceSubtitles;
621+
// outputTarget.value = row.TargetSubtitles;
622+
//
623+
// state.currentVideoData = row;
624+
// selectedKey.value = row.Id;
625+
// message.success("此链接视频已被下载,已跳转到该视频");
626+
// } else {
627+
// showPin.value = true;
628+
// state.loadingText = "正在下载请稍后...";
629+
//
630+
// console.log("准备下载");
631+
// ipcRenderer.send("call-yt-dlp", input.value, checkedValue.value);
632+
// }
633+
// };
635634
636635
// 子进程定义方法
637636
ipcRenderer.on("reply-output", (event: any, isSupport: boolean, text) => {

‎src/views/home/main.vue

+33-15
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,9 @@ import { useRouter } from "vue-router";
8282
8383
const message = useMessage();
8484
const router = useRouter();
85-
message.success("欢迎使用aehyok字幕下载器");
85+
message.success("欢迎使用aehyok视频转图文AI小工具");
8686
let videoPlayer = ref<Player>();
8787
88-
onMounted(async() => {
89-
await getAll();
90-
videoPlayer.value = new Player({
91-
id: "videoPlayer",
92-
// url: "http://s2.pstatp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo.mp4",
93-
url: "/command/2024-06-10-08-52-18/QxjzF9kt5Z0.webm",
94-
height: "300px",
95-
width: "100%",
96-
});
97-
98-
console.log(videoPlayer, "videoPlayer");
99-
});
100-
10188
const formRef = ref<FormInst | null>(null);
10289
10390
const model = reactive<any>({
@@ -112,6 +99,34 @@ const model = reactive<any>({
11299
const state = reactive({
113100
checkedValue: false,
114101
rule: {},
102+
executePath: "",
103+
middlePath: ""
104+
});
105+
106+
onMounted(async() => {
107+
let env = import.meta.env.MODE;
108+
state.middlePath = env == "development" ? "": "/resources";
109+
110+
ipcRenderer.send("call-execute-path");
111+
await getAll();
112+
113+
114+
console.log(videoPlayer, "videoPlayer");
115+
});
116+
117+
118+
// 子进程定义方法
119+
ipcRenderer.on("reply-execute-path", (event: any, executePath: string) => {
120+
console.log(event, "event-ipcRenderer");
121+
state.executePath = executePath;
122+
123+
videoPlayer.value = new Player({
124+
id: "videoPlayer",
125+
// url: "http://s2.pstatp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo.mp4",
126+
url: state.executePath + state.middlePath +"/command/2024-06-10-08-52-18/QxjzF9kt5Z0.webm",
127+
height: "300px",
128+
width: "100%",
129+
});
115130
});
116131
117132
const jumpDetail = (item: any) => {
@@ -192,17 +207,20 @@ const subtitleClick = async () => {
192207
ipcRenderer.on("reply-videoPath", async(event: any, type: string) => {
193208
console.log(type, "event-ipcRenderer");
194209
console.log(model.currentSelected, "model.currentSelected");
210+
211+
195212
if(type) {
196213
videoPlayer.value = new Player({
197214
id: "videoPlayer",
198-
url: `/command/${model.currentSelected.FolderDate}/${model.currentSelected.Id}${type}`,
215+
url: state.executePath + state.middlePath +`/command/${model.currentSelected.FolderDate}/${model.currentSelected.Id}${type}`,
199216
height: "300px",
200217
width: "100%",
201218
});
202219
}
203220
});
204221
205222
// 子进程定义方法
223+
206224
ipcRenderer.on("reply-output", async(event: any, isSupport: boolean, text) => {
207225
console.log(event, "event-ipcRenderer");
208226
if (!isSupport) {

0 commit comments

Comments
 (0)
Please sign in to comment.