typed versions object

This commit is contained in:
Yura Dupyn 2026-02-03 18:31:50 +01:00
parent 856ed3db93
commit 11388ea90b
3 changed files with 15 additions and 3 deletions

View file

@ -2,10 +2,14 @@
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('versions', {
import { Versions } from './versions';
const versions: Versions = {
node() { return process.versions.node; },
chrome() { return process.versions.chrome; },
electron() { return process.versions.electron; },
ping() { return ipcRenderer.invoke('ping'); }
});
};
contextBridge.exposeInMainWorld('versions', versions);

View file

@ -27,8 +27,9 @@
*/
import './index.scss';
import { Versions } from './versions';
console.log("hello world! yooo");
declare const versions: Versions; // preload
const information = document.getElementById('info');
information.innerText = `This app is using Chrome (v${versions.chrome()}), Node.js (v${versions.node()}), and Electron (v${versions.electron()})`;

7
src/versions.ts Normal file
View file

@ -0,0 +1,7 @@
export type Versions = {
node: () => string;
chrome: () => string;
electron: () => string;
ping: () => Promise<string>;
}