-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a83c06
commit ffd503d
Showing
16 changed files
with
291 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import path from 'path'; | ||
import { AppConfig } from './interfaces/app-config'; | ||
|
||
const isDev: boolean = process.env.NODE_ENV === 'development'; | ||
|
||
export const config = { | ||
appName: 'Comet', | ||
productName: 'comet', | ||
title: 'Comet | Video Converter', | ||
appId: 'com.github.comet', | ||
icons: path.join(__dirname, 'assets', 'images', 'icon', 'icon.png'), | ||
isDev, | ||
directories: { | ||
output: 'out', | ||
}, | ||
width: isDev ? 1200 : 700, | ||
height: 600, | ||
resizable: false, | ||
show: false, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
nodeIntegration: false, | ||
contextIsolation: true, | ||
} | ||
} as AppConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const SUPPORTED_FORMATS = [ | ||
'mp4', 'webm', 'ogg', 'flv', 'avi', | ||
'mov', 'wmv', '3gp', 'mkv', 'm4v', | ||
'mpg', 'mpeg', 'vob', 'ts', 'asf', | ||
'f4v', 'h264', 'hevc', 'm2ts', 'm2v', | ||
'mts', 'ogv', 'rm', 'swf', 'xvid', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum Channel { | ||
CONVERSION_PROGRESS = 'conversion-progress', | ||
CONVERSION_ERROR = 'conversion-error', | ||
DIALOG_SELECT_DIRECTORY = 'dialog:selectDirectory', | ||
GET_DOWNLOADS_PATH = 'getDownloadsPath', | ||
CONVERT_VIDEO = 'convertVideo', | ||
FFMPEG_STATUS = 'ffmpeg-status', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export enum Event { | ||
READY = 'ready', | ||
WINDOW_ALL_CLOSED = 'window-all-closed', | ||
ACTIVATE = 'activate', | ||
DIALOG_SELECT_DIRECTORY = 'dialog:selectDirectory', | ||
PRROGRESS = 'progress', | ||
END = 'end', | ||
ERROR = 'error', | ||
UNCAUGHT_EXCEPTION = 'uncaughtException', | ||
READY_TO_SHOW = 'ready-to-show', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Platform { | ||
WINDOWS = 'win32', | ||
MAC = 'darwin', | ||
LINUX = 'linux', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum ShortCut { | ||
RELOAD = 'CmdOrCtrl+R', | ||
RELOAD_F5 = 'F5', | ||
TOGGLE_DEV_TOOLS = 'CmdOrCtrl+Shift+I', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BrowserWindowConstructorOptions } from 'electron'; | ||
|
||
export interface AppConfig extends BrowserWindowConstructorOptions { | ||
appName: string, | ||
productName: string, | ||
title: string, | ||
appId: string, | ||
isDev: boolean, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IpcMainInvokeEvent } from 'electron'; | ||
import { FfmpegCommand } from 'fluent-ffmpeg'; | ||
import { Channel } from '../enums/channel'; | ||
import { Event } from '../enums/event'; | ||
|
||
/** | ||
* Handle the video conversion process. | ||
*/ | ||
export async function handleConversion( | ||
ffmpeg: (filePath: string) => FfmpegCommand, | ||
event: IpcMainInvokeEvent, | ||
filePath: string, | ||
outputFilePath: string, | ||
outputFormat: string | ||
): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
ffmpeg(filePath) | ||
.toFormat(outputFormat) | ||
.on(Event.PRROGRESS, (progress) => { | ||
if (progress.percent) { | ||
event.sender.send( | ||
Channel.CONVERSION_PROGRESS, | ||
progress | ||
); | ||
} | ||
}) | ||
.on(Event.END, () => resolve(outputFilePath)) | ||
.on(Event.ERROR, (error) => { | ||
event.sender.send( | ||
Channel.CONVERSION_ERROR, | ||
`FFmpeg error: ${error.message}` | ||
); | ||
reject(error); | ||
}) | ||
.save(outputFilePath); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import fs from 'fs'; | ||
import { execSync } from 'child_process'; | ||
import ffmpeg from 'fluent-ffmpeg'; | ||
import { App, IpcMain, Dialog } from 'electron'; | ||
|
||
/** | ||
* Get the path to the FFmpeg binary. | ||
* | ||
* @throws {Error} Will throw an error if the FFmpeg binary is not found. | ||
*/ | ||
export function getFfmpegPath(ipcMain: IpcMain): string { | ||
let ffmpegStatic: string | undefined; | ||
|
||
try { | ||
const ffmpegPath = execSync('which ffmpeg').toString().trim(); | ||
|
||
if (fs.existsSync(ffmpegPath)) { | ||
return ffmpegPath; | ||
} | ||
} catch (error) { | ||
ipcMain.emit('ffmpeg-status', 'System FFmpeg not found, using ffmpeg-static'); | ||
} | ||
|
||
if (typeof process !== 'undefined' && process.versions && process.versions.node) { | ||
ffmpegStatic = require('ffmpeg-static'); | ||
} | ||
|
||
if (ffmpegStatic) { | ||
return ffmpegStatic; | ||
} | ||
|
||
throw new Error('FFmpeg binary not found'); | ||
} | ||
|
||
/** | ||
* Create a FFmpeg command instance. | ||
*/ | ||
export function makeFfmpeg( | ||
app: App, | ||
ipcMain: IpcMain, | ||
dialog: Dialog | ||
): (filePath: string) => ffmpeg.FfmpegCommand { | ||
const ffmpegPath = getFfmpegPath(ipcMain); | ||
|
||
if (ffmpegPath) { | ||
try { | ||
fs.chmodSync(ffmpegPath, 0o755); | ||
ffmpeg.setFfmpegPath(ffmpegPath); | ||
} catch (err) { | ||
dialog.showErrorBox('FFmpeg Error', `Failed to set executable permissions or FFmpeg path: ${err.message}`); | ||
app.quit(); | ||
} | ||
} else { | ||
dialog.showErrorBox('FFmpeg Error', 'FFmpeg binary not found'); | ||
app.quit(); | ||
} | ||
|
||
return (filePath: string) => ffmpeg(filePath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
BrowserWindow, | ||
globalShortcut, | ||
} from 'electron'; | ||
import path from 'path'; | ||
import { config } from '../config'; | ||
import { ShortCut } from '../enums/shortcut'; | ||
import { Event } from '../enums/event'; | ||
|
||
/** | ||
* The main application window. | ||
*/ | ||
let mainWindow: BrowserWindow | undefined = undefined; | ||
|
||
/** | ||
* Create the main application window. | ||
*/ | ||
export function createWindow(): BrowserWindow { | ||
mainWindow = new BrowserWindow({ ...config }); | ||
|
||
mainWindow.once(Event.READY_TO_SHOW, () => mainWindow.show()); | ||
|
||
const mainWindowUrl: string = config.isDev | ||
? process.env.MAIN_WINDOW_VITE_DEV_SERVER_URL || 'default_dev_url' | ||
: `file://${path.join(__dirname, '../renderer', process.env.MAIN_WINDOW_VITE_NAME || 'default_name', 'index.html')}`; | ||
|
||
mainWindow.loadURL(mainWindowUrl); | ||
|
||
if (config.isDev) { | ||
mainWindow.webContents.openDevTools(); | ||
} | ||
|
||
if (!config.isDev) { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
globalShortcut.register(ShortCut.RELOAD, () => { }); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
globalShortcut.register(ShortCut.RELOAD_F5, () => { }); | ||
} | ||
|
||
return mainWindow; | ||
} | ||
|
||
export { | ||
mainWindow, | ||
}; |
Oops, something went wrong.