Skip to content

Commit

Permalink
Start config work
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanleclaire committed Mar 9, 2022
1 parent ab775a1 commit 61d3841
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions assets/migrations/0002_config.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE config (
id INTEGER PRIMARY KEY,
key TEXT NOT NULL,
val TEXT NOT NULL,
);
15 changes: 15 additions & 0 deletions src/main/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { WBConfigRequest, WBConfigResponse } from 'types/types';
import { db } from './db';

async function wbConfig(msg: WBConfigRequest): Promise<WBConfigResponse> {
const { action, key } = msg;
if (action === 'set') {
const { val } = msg;
db.run('UPDATE config SET val = ? WHERE name = ?', val, key);
return { val };
}
const val = await db.get('SELECT val FROM config WHERE name = ?', key);
return { val };
}

export default wbConfig;
4 changes: 4 additions & 0 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './programChanges';
import { RESOURCES_PATH } from './const';
import { db, initDB } from './db';
import wbConfig from './config';

export default class AppUpdater {
constructor() {
Expand Down Expand Up @@ -74,6 +75,9 @@ ipcMain.on(
case 'unsubscribe-program-changes':
await unsubscribeProgramChanges(msg);
break;
case 'config':
res = await wbConfig(msg);
break;
default:
}
logger.info('OK', { method, ...res });
Expand Down
3 changes: 3 additions & 0 deletions src/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ contextBridge.exposeInMainWorld('electron', {
unsubscribeProgramChanges(msg) {
send('unsubscribe-program-changes', msg);
},
config(msg) {
send('config', msg);
},
on(method, func) {
ipcRenderer.on(method, (event, ...args) => func(...args));
},
Expand Down
10 changes: 10 additions & 0 deletions src/types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export type FetchAnchorIDLRequest = {
programID: string;
};

export type WBConfigRequest = {
key: string;
val?: string;
action: string;
};

export type WBConfigResponse = {
val: string | undefined;
};

export type ProgramAccountChange = {
pubKey: string;
net: Net;
Expand Down

0 comments on commit 61d3841

Please sign in to comment.