diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..02cdcc9 --- /dev/null +++ b/.husky/pre-commit @@ -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 diff --git a/main/background.ts b/main/background.ts index b0b07e0..1471ae2 100644 --- a/main/background.ts +++ b/main/background.ts @@ -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"; @@ -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) => { diff --git a/main/preload.ts b/main/preload.ts index de55c40..2d21a22 100644 --- a/main/preload.ts +++ b/main/preload.ts @@ -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 { - return new Promise((resolve: (...args: unknown[]) => void) => { - const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => { - ipcRenderer.off(channel, subscription); - resolve(...args); + requestMetrics: function (): Promise { + 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) { diff --git a/main/types/Minor.ts b/main/types/Minor.ts index c82fdd4..0dd0725 100644 --- a/main/types/Minor.ts +++ b/main/types/Minor.ts @@ -4,11 +4,7 @@ export type MinorParser = { type: string; metrics: { value: string; - labels: { - [key: string]: string; - }; - buckets: { - [key: string]: string; - }; + labels: Record; + buckets: Record; }[]; }; diff --git a/package.json b/package.json index 9e2c624..5fa2729 100644 --- a/package.json +++ b/package.json @@ -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}\"", diff --git a/renderer/pages/dashboard.tsx b/renderer/pages/dashboard.tsx index 0391af3..3eff4e7 100644 --- a/renderer/pages/dashboard.tsx +++ b/renderer/pages/dashboard.tsx @@ -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)); })(); diff --git a/types/metrics.ts b/types/metrics.ts new file mode 100644 index 0000000..afe1e0c --- /dev/null +++ b/types/metrics.ts @@ -0,0 +1,7 @@ +export type Metrics = { + data_unpackaged: number; + data_packaged: number; + hash_rate: number; + earnings: number; + vdf_time_lower_bound: number; +}