From 6946a7821b240643ad8cbe7877b47bb93d1ad1ca Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 Jul 2023 16:15:34 +0200 Subject: [PATCH] tutorial-preload --- pages/index.html | 9 ++++++++- src/preload.ts | 13 +++++-------- src/renderer.ts | 1 - src/scripts/renderer.ts | 6 ++++++ 4 files changed, 19 insertions(+), 10 deletions(-) delete mode 100644 src/renderer.ts create mode 100644 src/scripts/renderer.ts diff --git a/pages/index.html b/pages/index.html index d91ae22..69d8e82 100644 --- a/pages/index.html +++ b/pages/index.html @@ -6,9 +6,16 @@ http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'" /> + Discord Video Sharing - +

Discord Video Sharing

+

+ + diff --git a/src/preload.ts b/src/preload.ts index 0a69c7c..a734009 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -1,10 +1,7 @@ -window.addEventListener("DOMContentLoaded", () => { - const replaceText = (selector: string, text: string) => { - const element = document.getElementById(selector); - if (element) element.innerText = text; - }; +import { contextBridge } from "electron"; - for (const dependency of ["chrome", "node", "electron"]) { - replaceText(`${dependency}-version`, process.versions[dependency]); - } +contextBridge.exposeInMainWorld("versions", { + node: () => process.versions.node, + chrome: () => process.versions.chrome, + electron: () => process.versions.electron, }); diff --git a/src/renderer.ts b/src/renderer.ts deleted file mode 100644 index 702f428..0000000 --- a/src/renderer.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("hello"); diff --git a/src/scripts/renderer.ts b/src/scripts/renderer.ts new file mode 100644 index 0000000..cc33137 --- /dev/null +++ b/src/scripts/renderer.ts @@ -0,0 +1,6 @@ +/* Preload variables */ +var versions: any; + +const information = document.getElementById("info"); + +information.innerText = `Cette application utilise Chrome (v${versions.chrome()}), Node.js (v${versions.node()}), et Electron (v${versions.electron()})`;