typed versions object
This commit is contained in:
parent
856ed3db93
commit
11388ea90b
3 changed files with 15 additions and 3 deletions
|
|
@ -2,10 +2,14 @@
|
||||||
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
|
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
|
||||||
import { contextBridge, ipcRenderer } from 'electron';
|
import { contextBridge, ipcRenderer } from 'electron';
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('versions', {
|
import { Versions } from './versions';
|
||||||
|
|
||||||
|
const versions: Versions = {
|
||||||
node() { return process.versions.node; },
|
node() { return process.versions.node; },
|
||||||
chrome() { return process.versions.chrome; },
|
chrome() { return process.versions.chrome; },
|
||||||
electron() { return process.versions.electron; },
|
electron() { return process.versions.electron; },
|
||||||
ping() { return ipcRenderer.invoke('ping'); }
|
ping() { return ipcRenderer.invoke('ping'); }
|
||||||
});
|
};
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld('versions', versions);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
import { Versions } from './versions';
|
||||||
|
|
||||||
console.log("hello world! yooo");
|
declare const versions: Versions; // preload
|
||||||
|
|
||||||
const information = document.getElementById('info');
|
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()})`;
|
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
7
src/versions.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
export type Versions = {
|
||||||
|
node: () => string;
|
||||||
|
chrome: () => string;
|
||||||
|
electron: () => string;
|
||||||
|
ping: () => Promise<string>;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue