add ffmpeg to context bridge

This commit is contained in:
Mylloon 2023-07-29 19:23:18 +02:00
parent 0255515f77
commit 8829b9fe92
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
6 changed files with 37 additions and 21 deletions

13
css/style.css Normal file
View file

@ -0,0 +1,13 @@
@media (prefers-color-scheme: dark) {
body {
background: rgb(18, 18, 18);
color: rgb(240, 240, 240);
}
}
@media (prefers-color-scheme: light) {
body {
background: rgb(240, 240, 240);
color: rgb(18, 18, 18);
}
}

View file

@ -10,6 +10,9 @@
http-equiv="X-Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<title>Discord Video Sharing</title>
</head>
<body>

View file

@ -1,29 +1,34 @@
import { BrowserWindow, app, ipcMain } from "electron";
import path = require("path");
/* import ffmpegPath = require("ffmpeg-static"); */
import ffmpegPath = require("ffmpeg-static");
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
width: 1280,
height: 720,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
});
win.loadFile(path.join(path.resolve(__dirname, ".."), "pages", "index.html"));
win.webContents.openDevTools(); // debug
};
app.whenReady().then(() => {
ipcMain.handle("ping", () => "pong");
ipcMain.handle("ffmpeg", () => ffmpegPath);
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
if (process.platform !== "darwin") {
app.quit();
}
});

View file

@ -1,8 +1,5 @@
import { contextBridge, ipcRenderer } from "electron";
contextBridge.exposeInMainWorld("versions", {
node: () => process.versions.node,
chrome: () => process.versions.chrome,
electron: () => process.versions.electron,
ping: () => ipcRenderer.invoke("ping"),
contextBridge.exposeInMainWorld("internals", {
ffmpeg: () => ipcRenderer.invoke("ffmpeg"),
});

View file

@ -1,13 +1,11 @@
/* Preload variables */
var versions: any;
/* Context bridge */
let internals: {
ffmpeg: () => Promise<string>;
};
const information = document.getElementById("info");
information.innerText = `Cette application utilise Chrome (v${versions.chrome()}), Node.js (v${versions.node()}), et Electron (v${versions.electron()})`;
const func = async () => {
const response = await versions.ping();
const get_ffmpeg = async () => {
const response = await internals.ffmpeg();
console.log(response);
};
func();
get_ffmpeg();

View file

@ -9,5 +9,5 @@
"*": ["node_modules/*"]
}
},
"include": ["src/**/*"]
"include": ["src/**/*.ts"]
}