-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify config storage IPC code (#126)
* 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
1 parent
cbf6193
commit b2b9ff7
Showing
10 changed files
with
85 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |
Oops, something went wrong.