From ffd503db947c994b4eb19ca1a51a48a563ce0c7b Mon Sep 17 00:00:00 2001 From: Jerome Thayananthajothy Date: Sat, 17 Aug 2024 02:14:00 +0100 Subject: [PATCH] Refactor app --- .editorconfig | 2 +- .eslintrc.json | 8 +- forge.config.ts | 7 ++ src/App.vue | 32 +++---- src/config.ts | 25 ++++++ src/consts/formats.ts | 7 ++ src/enums/channel.ts | 8 ++ src/enums/event.ts | 11 +++ src/enums/platform.ts | 5 ++ src/enums/shortcut.ts | 5 ++ src/interfaces/app-config.ts | 9 ++ src/lib/conversion-handler.ts | 37 ++++++++ src/lib/ffmpeg.ts | 59 +++++++++++++ src/lib/window-manager.ts | 45 ++++++++++ src/main.ts | 157 ++++++++++------------------------ src/preload.ts | 11 +-- 16 files changed, 291 insertions(+), 137 deletions(-) create mode 100644 src/config.ts create mode 100644 src/consts/formats.ts create mode 100644 src/enums/channel.ts create mode 100644 src/enums/event.ts create mode 100644 src/enums/platform.ts create mode 100644 src/enums/shortcut.ts create mode 100644 src/interfaces/app-config.ts create mode 100644 src/lib/conversion-handler.ts create mode 100644 src/lib/ffmpeg.ts create mode 100644 src/lib/window-manager.ts diff --git a/.editorconfig b/.editorconfig index 2611576..13fabf0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [{*.html,*.js,*.json,*.md,*.ts,*.yml,*eslintrc}] indent_style = space indent_size = 2 -insert_final_newline = true +insert_final_newline = false max_line_length = 160 trim_trailing_whitespace = true diff --git a/.eslintrc.json b/.eslintrc.json index 076062c..4ff49b5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,7 +20,13 @@ { "SwitchCase": 1 } - ] + ], + "max-len": [ + "error", + { + "code": 80 + } + ], }, "ignorePatterns": [ "*.test.ts" diff --git a/forge.config.ts b/forge.config.ts index 9ed7aaf..d1cf89a 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -13,6 +13,13 @@ const config: ForgeConfig = { unpack: '**/node_modules/ffmpeg-static/ffmpeg', }, icon: 'src/assets/images/icon/icon', + extraResource: 'node_modules/ffmpeg-static/ffmpeg', + osxSign: {}, + osxNotarize: { + appleId: process.env.APPLE_ID, + appleIdPassword: process.env.APPLE_ID_PASSWORD, + teamId: process.env.TEAM_ID, + }, }, rebuildConfig: {}, makers: [ diff --git a/src/App.vue b/src/App.vue index 33175dd..e424f4c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,6 +23,8 @@ import { TrashIcon, ReloadIcon, } from '@radix-icons/vue'; +import { Channel } from './enums/channel'; +import { SUPPORTED_FORMATS } from './consts/formats'; const files = ref(); const saveDirectory = ref(); @@ -35,18 +37,20 @@ onMounted(async () => { saveDirectory.value = await window.electron.getDownloadsPath(); // Listen for backend messages - window.electron.on('ffmpeg-status', (_event: any, message: string) => { + window.electron.on(Channel.FFMPEG_STATUS, (_event: any, message: string) => { toast({ title: 'FFmpeg Status', description: message, }); }); - window.electron.on('conversion-progress', (_event: any, { filePath, progress }: { filePath: string, progress: number; }) => { + window.electron.on(Channel.CONVERSION_PROGRESS, ( + _event: any, { filePath, progress }: { filePath: string, progress: number; } + ) => { conversionProgress.value[filePath] = progress; }); - window.electron.on('conversion-error', (_event: any, error: string) => { + window.electron.on(Channel.CONVERSION_ERROR, (_event: any, error: string) => { converting.value = false; toast({ title: 'Error', @@ -58,21 +62,13 @@ onMounted(async () => { onUnmounted(() => { // Cleanup IPC listeners to avoid memory leaks - window.electron.removeAllListeners('ffmpeg-status'); - window.electron.removeAllListeners('conversion-progress'); - window.electron.removeAllListeners('conversion-error'); + window.electron.removeAllListeners(Channel.FFMPEG_STATUS); + window.electron.removeAllListeners(Channel.CONVERSION_PROGRESS); + window.electron.removeAllListeners(Channel.CONVERSION_ERROR); }); const emit = defineEmits(['files-uploaded']); -const CONVERSION_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', -]; - function handleUpload(uploads: FileList) { files.value = Array.from(uploads); } @@ -116,7 +112,11 @@ async function convertFiles() { const outputFormat = convertTo.value; const outputDirectory = saveDirectory.value; - const outputFilePath = await window.electron.convertVideo(filePath, outputFormat, outputDirectory); + const outputFilePath = await window.electron.convertVideo( + filePath, + outputFormat, + outputDirectory + ); toast({ title: 'File converted', @@ -207,7 +207,7 @@ async function convertFiles() {
    -
  • +