-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (65 loc) · 2.12 KB
/
index.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
const path = require('path');
const electron = require('electron');
const ffmpeg = require('fluent-ffmpeg');
const ConvTray = require('./myapp/conv_tray');
const _ = require('lodash');
const { app, BrowserWindow, ipcMain, shell, Menu } = electron;
let mainWindow;
let tray;
app.on('ready', () => {
mainWindow = new BrowserWindow({
height: 600,
width: 800,
frame: true,
icon: `${__dirname}/src/assets/64x64.png`,
webPreferences: { backgroundThrottling: true },
});
mainWindow.loadURL(`file://${__dirname}/src/index.html`);
const mainMenu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(mainMenu);
const iconName = process.platform === 'win32' ? '[email protected]' : 'iconTemplate.png';
const iconPath = path.join(__dirname, `./src/assets/${iconName}`);
tray = new ConvTray(iconPath, mainWindow);
mainWindow.on('minimize',function(event){
event.preventDefault();
mainWindow.hide();
});
mainWindow.on('closed', () => {
mainWindow = null;
});
});
const menuTemplate = [{}];
ipcMain.on('videos:added', (event, videos) => {
const promises = _.map(videos, video => {
return new Promise((resolve, reject) => {
ffmpeg.ffprobe(video.path, (err, metadata) => {
video.duration = metadata.format.duration;
video.format = 'avi';
resolve(video);
});
});
});
Promise.all(promises)
.then((results) => {
mainWindow.webContents.send('metadata:complete', results);
});
});
ipcMain.on('conversion:start', (event, videos) => {
_.each(videos, video => {
const outputDirectory = video.path.split(video.name)[0];
const outputName = video.name.split('.')[0]
const outputPath = `${outputDirectory}${outputName}.${video.format}`;
ffmpeg(video.path)
.output(outputPath)
.on('progress', ({ timemark }) =>
mainWindow.webContents.send('conversion:progress', { video, timemark })
)
.on('end', () =>
mainWindow.webContents.send('conversion:end', { video, outputPath })
)
.run();
});
});
ipcMain.on('folder:open', (event, outputPath) => {
shell.showItemInFolder(outputPath);
});