From 0255515f77adb8b3910fc8789f888542740ce1aa Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 Jul 2023 16:23:38 +0200 Subject: [PATCH] add ping function --- src/main.ts | 4 +++- src/preload.ts | 3 ++- src/scripts/renderer.ts | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 2cb61a6..cbdd499 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow } from "electron"; +import { BrowserWindow, app, ipcMain } from "electron"; import path = require("path"); /* import ffmpegPath = require("ffmpeg-static"); */ @@ -15,6 +15,8 @@ const createWindow = () => { }; app.whenReady().then(() => { + ipcMain.handle("ping", () => "pong"); + createWindow(); app.on("activate", () => { diff --git a/src/preload.ts b/src/preload.ts index a734009..6b04f68 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -1,7 +1,8 @@ -import { contextBridge } from "electron"; +import { contextBridge, ipcRenderer } from "electron"; contextBridge.exposeInMainWorld("versions", { node: () => process.versions.node, chrome: () => process.versions.chrome, electron: () => process.versions.electron, + ping: () => ipcRenderer.invoke("ping"), }); diff --git a/src/scripts/renderer.ts b/src/scripts/renderer.ts index cc33137..336c2c7 100644 --- a/src/scripts/renderer.ts +++ b/src/scripts/renderer.ts @@ -4,3 +4,10 @@ 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()})`; + +const func = async () => { + const response = await versions.ping(); + console.log(response); +}; + +func();