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" http-equiv="X-Content-Security-Policy"
content="default-src 'self'; script-src 'self'" content="default-src 'self'; script-src 'self'"
/> />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<title>Discord Video Sharing</title> <title>Discord Video Sharing</title>
</head> </head>
<body> <body>

View file

@ -1,29 +1,34 @@
import { BrowserWindow, app, ipcMain } from "electron"; import { BrowserWindow, app, ipcMain } from "electron";
import path = require("path"); import path = require("path");
/* import ffmpegPath = require("ffmpeg-static"); */ import ffmpegPath = require("ffmpeg-static");
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 1280,
height: 600, height: 720,
webPreferences: { webPreferences: {
preload: path.join(__dirname, "preload.js"), preload: path.join(__dirname, "preload.js"),
}, },
}); });
win.loadFile(path.join(path.resolve(__dirname, ".."), "pages", "index.html")); win.loadFile(path.join(path.resolve(__dirname, ".."), "pages", "index.html"));
win.webContents.openDevTools(); // debug
}; };
app.whenReady().then(() => { app.whenReady().then(() => {
ipcMain.handle("ping", () => "pong"); ipcMain.handle("ffmpeg", () => ffmpegPath);
createWindow(); createWindow();
app.on("activate", () => { app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow(); if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
}); });
}); });
app.on("window-all-closed", () => { 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"; import { contextBridge, ipcRenderer } from "electron";
contextBridge.exposeInMainWorld("versions", { contextBridge.exposeInMainWorld("internals", {
node: () => process.versions.node, ffmpeg: () => ipcRenderer.invoke("ffmpeg"),
chrome: () => process.versions.chrome,
electron: () => process.versions.electron,
ping: () => ipcRenderer.invoke("ping"),
}); });

View file

@ -1,13 +1,11 @@
/* Preload variables */ /* Context bridge */
var versions: any; let internals: {
ffmpeg: () => Promise<string>;
};
const information = document.getElementById("info"); const get_ffmpeg = async () => {
const response = await internals.ffmpeg();
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();
console.log(response); console.log(response);
}; };
func(); get_ffmpeg();

View file

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