Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/types2 #5

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run check:lint && npm run check:types
npm run format:renderer && npm run format:main
npm run check:lint && npm run check:types
npm run format:renderer && npm run format:main
8 changes: 5 additions & 3 deletions main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import serve from "electron-serve";
import { createWindow } from "./helpers";
import parsePrometheusTextFormat from "parse-prometheus-text-format";
import { MinorParser } from "./types/Minor";
import { Metrics } from "../types/metrics";

const isProd = process.env.NODE_ENV === "production";

Expand Down Expand Up @@ -86,14 +87,15 @@ ipcMain.on("metrics", async (event) => {
}
}
}

event.reply("metrics", {
const metrics: Metrics = {
data_unpackaged,
data_packaged,
hash_rate,
earnings,
vdf_time_lower_bound,
});
};

event.reply("metrics", metrics);
});

ipcMain.on("open-url", async (event, arg) => {
Expand Down
15 changes: 8 additions & 7 deletions main/preload.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron";
import { Metrics } from "../types/metrics";

const handler = {
send(channel: string, value: unknown) {
ipcRenderer.send(channel, value);
},
request: function (channel: string, value: unknown): Promise<unknown> {
return new Promise((resolve: (...args: unknown[]) => void) => {
const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => {
ipcRenderer.off(channel, subscription);
resolve(...args);
requestMetrics: function (): Promise<Metrics> {
return new Promise((resolve: (res: Metrics) => void) => {
const subscription = (_event: IpcRendererEvent, res: Metrics) => {
ipcRenderer.off("metrics", subscription);
resolve(res);
};
ipcRenderer.on(channel, subscription);
ipcRenderer.send(channel, value);
ipcRenderer.on("metrics", subscription);
ipcRenderer.send("metrics", {});
});
},
on(channel: string, callback: (...args: unknown[]) => void) {
Expand Down
8 changes: 2 additions & 6 deletions main/types/Minor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ export type MinorParser = {
type: string;
metrics: {
value: string;
labels: {
[key: string]: string;
};
buckets: {
[key: string]: string;
};
labels: Record<string, string>;
buckets: Record<string, string>;
}[];
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev": "nextron",
"build": "nextron build",
"postinstall": "electron-builder install-app-deps",
"check": "npm run check:lint && npm run check:types",
"check:lint": "npx eslint .",
"check:types": "npx tsc --noEmit",
"format:renderer": "prettier --write \"renderer/**/*.{js,jsx,ts,tsx,css}\"",
Expand Down
2 changes: 1 addition & 1 deletion renderer/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function DashboardPage() {

React.useEffect(() => {
(async () => {
const data = await window.ipc.request("metrics", {});
const data = await window.ipc.requestMetrics();

dispatch(setMinorState(data));
})();
Expand Down
7 changes: 7 additions & 0 deletions types/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type Metrics = {
data_unpackaged: number;
data_packaged: number;
hash_rate: number;
earnings: number;
vdf_time_lower_bound: number;
}