Skip to content

Commit

Permalink
Simplify config storage IPC code (#126)
Browse files Browse the repository at this point in the history
* checkpoint - use electron-cfg for window size, and delete files that just contain commented out cfg things

Signed-off-by: Sven Dowideit <[email protected]>

* simplest thing for config

Signed-off-by: Sven Dowideit <[email protected]>

* remove types that don't need to be global

Signed-off-by: Sven Dowideit <[email protected]>

* seems to work on arian

Signed-off-by: Sven Dowideit <[email protected]>

* Finally, figured out half of what i wanted to acheive yesterday

Signed-off-by: Sven Dowideit <[email protected]>

* finally hide all the config IPC inside the config slice

Signed-off-by: Sven Dowideit <[email protected]>
  • Loading branch information
SvenDowideit authored May 19, 2022
1 parent cbf6193 commit b2b9ff7
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 526 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@
"amplitude-js": "^8.12.0",
"bootstrap": "^5.1.3",
"command-exists": "^1.2.9",
"electron-cfg": "^1.2.7",
"electron-debug": "^3.2.0",
"electron-log": "^4.4.6",
"electron-promise-ipc": "^2.2.4",
"electron-updater": "^5.0.1",
"hexdump-nodejs": "^0.1.0",
"history": "^5.2.0",
Expand Down
198 changes: 0 additions & 198 deletions src/main/accounts.ts

This file was deleted.

45 changes: 28 additions & 17 deletions src/main/config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import {
ConfigAction,
ConfigMap,
WBConfigRequest,
WBConfigResponse,
} from '../types/types';
import db from './db';
import cfg from 'electron-cfg';
import promiseIpc from 'electron-promise-ipc';
import type { IpcMainEvent, IpcRendererEvent } from 'electron';

import { logger } from './logger';

async function wbConfig(msg: WBConfigRequest): Promise<WBConfigResponse> {
const { action, key } = msg;
if (action === ConfigAction.Set) {
const { val } = msg;
await db.config.set(key, val);
}
const values: ConfigMap = await db.config.all();
logger.info('config values', { values: JSON.stringify(values) });
return { values };
declare type IpcEvent = IpcRendererEvent & IpcMainEvent;

// NOTE: using the electron-cfg window size code can reault in the window shrinking every time the app restarts
// Sven has seen it on windows with one 4k screen at 100%, the other at 200%

// Need to import the file and call a function (from the main process) to get the IPC promise to exist.
export function initConfigPromises() {
// gets written to .\AppData\Roaming\SolanaWorkbench\electron-cfg.json on windows
promiseIpc.on('CONFIG-GetAll', (event: IpcEvent | undefined) => {
logger.silly('main: called CONFIG-GetAll', event);
const config = cfg.get('config');
if (!config) {
return {};
}
return config;
});
promiseIpc.on(
'CONFIG-Set',
(key: unknown, val: unknown, event?: IpcEvent | undefined) => {
logger.silly(`main: called CONFIG-Set, ${key}, ${val}, ${event}`);
return cfg.set(`config.${key}`, val);
}
);
}

export default wbConfig;
export default {};
Loading

0 comments on commit b2b9ff7

Please sign in to comment.