-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
96 lines (80 loc) · 3.02 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const MediaProcessor = require('./src/mediaProcessor');
const { validateMediaFile } = require('./src/validators');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 600,
height: 650,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
webSecurity: true
}
});
const htmlPath = path.join(__dirname, 'src', 'ui', 'index.html');
console.log('Loading HTML from:', htmlPath);
mainWindow.loadFile(htmlPath);
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
}
function setupApplication() {
ipcMain.handle('select-file', async () => {
try {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openFile'],
filters: [
{
name: 'Media Files',
extensions: ['jpg', 'jpeg', 'png', 'webp', 'gif', 'mp4', 'avi', 'mov', 'MOV', 'mkv', 'wmv']
}
]
});
if (!result.canceled && result.filePaths.length > 0) {
const filePath = result.filePaths[0];
console.log('Archivo seleccionado:', filePath);
const validation = await validateMediaFile(filePath);
console.log('Resultado de validación:', validation);
if (!validation.isValid) {
throw new Error('El archivo seleccionado no es un archivo multimedia válido');
}
return filePath;
}
return null;
} catch (error) {
console.error('Error en select-file:', error);
throw error;
}
});
ipcMain.handle('process-videos', async (event, { filePath, numberOfCopies }) => {
try {
console.log('Iniciando procesamiento:', { filePath, numberOfCopies });
const processor = new MediaProcessor(filePath);
processor.on('progress', (current) => {
mainWindow.webContents.send('progress-update', {
current,
total: numberOfCopies
});
});
const results = await processor.generateVariants(numberOfCopies);
return { success: true, results };
} catch (error) {
console.error('Error en process-media:', error);
return { success: false, error: error.message };
}
});
}
app.whenReady().then(() => {
setupApplication();
createWindow();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});