1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Resolve PR comments

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-26 10:52:16 -04:00
parent 664f1c07e5
commit 43df24cde3

View File

@ -54,36 +54,32 @@ export class AppPaths {
private static readonly ipcChannel = "get-app-paths"; private static readonly ipcChannel = "get-app-paths";
/** /**
* Inititalizes the local copy of the paths from electron * Initializes the local copy of the paths from electron.
*/ */
static init(): void { static async init(): Promise<void> {
logger.info(`[APP-PATHS]: initializing`); logger.info(`[APP-PATHS]: initializing`);
if (AppPaths.paths.get()) { if (AppPaths.paths.get()) {
logger.error("[APP-PATHS]: init called more than once"); return void logger.error("[APP-PATHS]: init called more than once");
return;
} }
if (ipcMain) { if (ipcMain) {
AppPaths.initMain(); AppPaths.initMain();
} else { } else {
AppPaths.initRenderer(); await AppPaths.initRenderer();
} }
} }
private static initMain(): void { private static initMain(): void {
AppPaths.paths.set(fromEntries( AppPaths.paths.set(fromEntries(pathNames.map(pathName => [pathName, app.getPath(pathName)])));
pathNames.map(pathName => [pathName, app.getPath(pathName)]) ipcMain.handle(AppPaths.ipcChannel, () => toJS(AppPaths.paths.get()));
));
ipcMain.on(AppPaths.ipcChannel, (event) => event.returnValue = toJS(AppPaths.paths.get()));
} }
private static initRenderer(): void { private static async initRenderer(): Promise<void> {
const paths = ipcRenderer.sendSync(AppPaths.ipcChannel); const paths = await ipcRenderer.invoke(AppPaths.ipcChannel);
if (!paths || typeof paths !== "object") { if (!paths || typeof paths !== "object") {
throw Object.assign(new Error("[APP-PATHS]: ipc channel returned unexpected data"), { data: paths }); throw Object.assign(new Error("[APP-PATHS]: ipc handler returned unexpected data"), { data: paths });
} }
AppPaths.paths.set(paths); AppPaths.paths.set(paths);