Skip to content

Commit

Permalink
Merge pull request #12 from ArweaveTeam/feature/node-configuration
Browse files Browse the repository at this point in the history
feat: node endpoint configuration via persistent storage
  • Loading branch information
hlolli authored Nov 21, 2023
2 parents a74f13c + 9386673 commit 6727536
Show file tree
Hide file tree
Showing 26 changed files with 682 additions and 220 deletions.
8 changes: 8 additions & 0 deletions main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ let mainWindow: BrowserWindow;

(async () => {
await app.whenReady();
// session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
// callback({
// responseHeaders: {
// ...details.responseHeaders,
// "Content-Security-Policy": ["script-src 'self' localhost:8888"],
// },
// });
// });

mainWindow = createWindow("main", {
width: 1000,
Expand Down
40 changes: 40 additions & 0 deletions main/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Store from "electron-store";
import { ArweaveMinerUiConfig, ArweaveNodeConfig } from "../types/config";

const schema = {
nodes: {
type: "array" as const,
items: {
type: "object" as const,
properties: {
name: {
type: "string" as const,
},
host: {
type: "string" as const,
},
port: {
type: "number" as const,
},
protocol: {
type: "string" as const,
},
},
required: ["name", "host", "port", "protocol"],
},
},
};

const store = new Store<ArweaveMinerUiConfig>({ schema });

export const configHandler = {
configGetNodes: () => {
console.log(store);
return store.get("nodes") || [];
},
configAppendNode: (node: ArweaveNodeConfig) => {
const currentNodes = store.get("nodes", []);
const newNodes = [...currentNodes, node];
store.set("nodes", newNodes);
},
};
4 changes: 3 additions & 1 deletion main/helpers/create-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export const createWindow = (
...state,
...options,
webPreferences: {
nodeIntegration: false,
nodeIntegration: true,
nodeIntegrationInWorker: true,
contextIsolation: true,
sandbox: false,
...options.webPreferences,
},
});
Expand Down
2 changes: 2 additions & 0 deletions main/preload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron";
import { configHandler } from "./config";
import { SetMetricsStateActionPayload } from "../types/metrics";

ipcRenderer.on("metricsPush", (_event, msg) => {
Expand Down Expand Up @@ -26,6 +27,7 @@ const handler = {
ipcRenderer.removeListener(channel, subscription);
};
},
...configHandler,
};

contextBridge.exposeInMainWorld("ipc", handler);
Expand Down
Loading

0 comments on commit 6727536

Please sign in to comment.