diff --git a/pages/index.html b/pages/index.html index f80e177..684ec8d 100644 --- a/pages/index.html +++ b/pages/index.html @@ -17,7 +17,6 @@

Discord Video Sharing

-

diff --git a/src/main.ts b/src/main.ts index a3bf19d..8751adc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,8 @@ const createWindow = () => { win.loadFile(path.join(path.resolve(__dirname, ".."), "pages", "index.html")); win.webContents.openDevTools(); // debug + + return win; }; const moviesFilter = { @@ -22,16 +24,6 @@ const moviesFilter = { extensions: ["mp4", "mkv"], } as FileFilter; -/** Ask user a file */ -const askFile = async () => { - return ( - await dialog.showOpenDialog({ - filters: [moviesFilter], - properties: ["openFile", "dontAddToRecent"], - }) - ).filePaths; -}; - const getNewFilename = (ogFile: string, part: string) => { const oldFile = path.parse(ogFile); return path.join(oldFile.dir, `${part}`.concat(oldFile.base)); @@ -43,18 +35,33 @@ const mergeAudio = (file: string) => { child_process.exec( `${ffmpegPath} -i "${file}" -filter_complex "[0:a]amerge=inputs=2[a]" -ac 1 -map 0:v -map "[a]" -c:v copy "${outFile}"` ); + + return outFile; }; app.whenReady().then(() => { + const win = createWindow(); + + /** Ask user a file */ + const askFile = async () => { + return dialog.showOpenDialogSync(win, { + filters: [moviesFilter], + properties: ["openFile", "dontAddToRecent"], + }); + }; + + /** Send confirmation to user */ + const confirmation = async (message: string) => { + dialog.showMessageBoxSync(win, { message }); + }; + /* Context bridge */ - ipcMain.handle("ffmpeg", () => ffmpegPath); ipcMain.handle("argv", () => process.argv); ipcMain.handle("allowedExtensions", () => moviesFilter); ipcMain.handle("askFile", () => askFile()); ipcMain.handle("mergeAudio", (_, file: string) => mergeAudio(file)); ipcMain.handle("exit", async () => app.quit()); - - createWindow(); + ipcMain.handle("confirmation", async (_, text: string) => confirmation(text)); app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) { diff --git a/src/preload.ts b/src/preload.ts index 13357a9..6648fea 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -2,10 +2,10 @@ import { contextBridge, ipcRenderer } from "electron"; /* Context bridge */ contextBridge.exposeInMainWorld("internals", { - ffmpeg: () => ipcRenderer.invoke("ffmpeg"), argv: () => ipcRenderer.invoke("argv"), allowedExtensions: () => ipcRenderer.invoke("allowedExtensions"), askFile: () => ipcRenderer.invoke("askFile"), mergeAudio: (file: string) => ipcRenderer.invoke("mergeAudio", file), exit: () => ipcRenderer.invoke("exit"), + confirmation: (text: string) => ipcRenderer.invoke("confirmation", text), }); diff --git a/src/scripts/renderer.ts b/src/scripts/renderer.ts index c07c2e3..39f6918 100644 --- a/src/scripts/renderer.ts +++ b/src/scripts/renderer.ts @@ -1,15 +1,16 @@ -/* Context bridge types */ +/** Context bridge types */ let internals: { - ffmpeg: () => Promise; argv: () => Promise; allowedExtensions: () => Promise<{ extensions: string[]; }>; askFile: () => Promise; - exit: () => any; - mergeAudio: (filename: string) => Promise; + exit: () => Promise; + mergeAudio: (filename: string) => Promise; + confirmation: (text: string) => Promise; }; +/** Search for a file */ const getFile = async () => { const allowedExtensions = (await internals.allowedExtensions()).extensions; const argv = await internals.argv(); @@ -27,9 +28,11 @@ const getFile = async () => { return file.join(""); }; +/** Main function */ const main = async () => { const file = await getFile(); - document.getElementById("info").innerText = file.concat(); - await internals.mergeAudio(file); + const newFile = await internals.mergeAudio(file); + await internals.confirmation(`File ok @ ${newFile}!`); + await internals.exit(); }; main();