Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/el3um4s/renderer-for-electron-system-info
Allow the renderer to get information about the version of Electron, Chrome and NodeJS used
https://github.com/el3um4s/renderer-for-electron-system-info
electron electronjs inter-process-communication ipc maximize minimize node nodejs npm restore ts typescript window window-controls
Last synced: about 1 month ago
JSON representation
Allow the renderer to get information about the version of Electron, Chrome and NodeJS used
- Host: GitHub
- URL: https://github.com/el3um4s/renderer-for-electron-system-info
- Owner: el3um4s
- License: mit
- Created: 2022-08-15T20:47:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-09T03:44:59.000Z (almost 2 years ago)
- Last Synced: 2024-10-18T21:37:50.096Z (2 months ago)
- Topics: electron, electronjs, inter-process-communication, ipc, maximize, minimize, node, nodejs, npm, restore, ts, typescript, window, window-controls
- Language: TypeScript
- Homepage:
- Size: 532 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# RENDERER for Electron: System Info
Allow the renderer to get information about the version of Electron, Chrome and NodeJS
NPM link: [@el3um4s/renderer-for-electron-system-info](https://www.npmjs.com/package/@el3um4s/renderer-for-electron-system-info)
Use [@el3um4s/ipc-for-electron](https://www.npmjs.com/package/@el3um4s/ipc-for-electron) and [@el3um4s/ipc-for-electron-system-info](https://www.npmjs.com/package/@el3um4s/ipc-for-electron-system-info) to allow communication between Electron and a web page
### Install and use the package
To use the package in a project:
```bash
npm i @el3um4s/renderer-for-electron-system-info
```Or with Electron:
```bash
npm i @el3um4s/renderer-for-electron-system-info @el3um4s/ipc-for-electron-system-info @el3um4s/ipc-for-electron
```Then the `preload.ts` file:
```ts
import { generateContextBridge } from "@el3um4s/ipc-for-electron";
import systemInfo from "@el3um4s/ipc-for-electron-system-info";const listAPI = [systemInfo];
generateContextBridge(listAPI);
```In the renderer file:
```ts
import systemInfo from "@el3um4s/renderer-for-electron-system-info";
let isWindows = false;systemInfo.requestIsWindows({
callback: (data) => {
isWindows = data.isWindows;
},
});let app: string = "-";
let chrome: string = "-";
let node: string = "-";
let electron: string = "-";systemInfo.requestSystemInfo({
callback: (data) => {
chrome = data.chrome;
node = data.node;
electron = data.electron;
app = data.app;
},
});
```In the renderer you can use:
```ts
let isWindows = false;globalThis.api.systemInfo.send("requestIsWindows", null);
globalThis.api.systemInfo.receive("getIsWindows", (data) => {
isWindows = data.isWindows;
});let chrome: string = "-";
let node: string = "-";
let electron: string = "-";
let app: string = "-";globalThis.api.systemInfo.send("requestSystemInfo", null);
globalThis.api.systemInfo.receive("getSystemInfo", (data) => {
chrome = data.chrome;
node = data.node;
electron = data.electron;
app = data.app;
});
```### API: Electron Side
- `requestSystemInfo` - Request the version of Electron, Chrome and NodeJS. The response is sent to the `getSystemInfo` channel
- `requestIsWindows` - Request if the OS is Windows. The response is sent to the `getIsWindows` channel### API: Renderer Side - Request
`requestSystemInfo = async (options: { callback?: (arg0: SystemInfo) => void; apiKey?: string; }): Promise`
example:
```ts
import systemInfo from "@el3um4s/renderer-for-electron-system-info";let app: string = "-";
let chrome: string = "-";
let node: string = "-";
let electron: string = "-";systemInfo.requestSystemInfo({
apiKey: "ipc",
callback: (data) => {
console.log("DATA OK", data);
chrome = data.chrome;
node = data.node;
electron = data.electron;
app = data.app;
},
});
````requestIsWindows = async (options: { callback?: (arg0: IsWindows) => void; apiKey?: string; }): Promise`
example:
```ts
import systemInfo from "@el3um4s/renderer-for-electron-system-info";let isWindows = false;
systemInfo.requestIsWindows({
apiKey: "ipc",
callback: (data) => {
console.log("DATA OK", data);
isWindows = data.isWindows;
},
});
```### API: Renderer Side - Response
`on.getSystemInfo = async (options: { callback?: (arg0: SystemInfo) => void; apiKey?: string; }): Promise`
example:
```ts
import systemInfo from "@el3um4s/renderer-for-electron-system-info";let app: string = "-";
let chrome: string = "-";
let node: string = "-";
let electron: string = "-";
systemInfo.requestSystemInfo();systemInfo.on.getSystemInfo({
apiKey: "ipc",
callback: (data) => {
console.log("DATA OK", data);
chrome = data.chrome;
node = data.node;
electron = data.electron;
app = data.app;
},
});
````on.getIsWindows = async (options: { callback?: (arg0: IsWindows) => void; apiKey?: string; }): Promise`
example:
```ts
import systemInfo from "@el3um4s/renderer-for-electron-system-info";let isWindows = false;
systemInfo.requestIsWindows();
systemInfo.on.getIsWindows({
apiKey: "ipc",
callback: (data) => {
console.log("DATA OK", data);
isWindows = data.isWindows;
},
});
```### Types
**SystemInfo**
```ts
interface SystemInfo {
chrome: string;
node: string;
electron: string;
app: string;
}
```**IsWindows**
```ts
interface IsWindows {
isWindows: boolean;
}
```**DefaultApiKey**
```ts
type DefaultApiKey = "ipc";
```