From aab9ae136d001c514e8fa22fedf9e81d4a58e1de Mon Sep 17 00:00:00 2001 From: Enrique Hernandez Date: Sat, 17 Apr 2021 12:57:22 -0400 Subject: [PATCH] add userData config path to helper functions --- src/background/helpers.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/background/helpers.ts b/src/background/helpers.ts index bd3d279..f0074fb 100644 --- a/src/background/helpers.ts +++ b/src/background/helpers.ts @@ -1,7 +1,9 @@ import fs from 'fs'; import { backgroundMitt } from "@/modules/emitter"; import { SessionState, WindowState } from "@/types"; +import { app } from "electron"; +const configPath = app.getPath("userData"); export const ipcEmit = (channel: string, payload: any) => { backgroundMitt.emit('ipc-renderer', { @@ -14,7 +16,7 @@ export const loadState = (fileName: string): SessionState => { let state: SessionState; try { - state = JSON.parse(fs.readFileSync(fileName).toString()); + state = JSON.parse(fs.readFileSync(configPath + fileName).toString()); } catch (error) { @@ -32,7 +34,7 @@ export const loadWinState = (fileName: string): WindowState => { let state: WindowState; try { - state = JSON.parse(fs.readFileSync(fileName).toString()); + state = JSON.parse(fs.readFileSync(configPath + fileName).toString()); } catch (error) { @@ -51,7 +53,7 @@ export const loadWinState = (fileName: string): WindowState => { // Save session or window state. export const saveToJson = (fileName: string, data: any) => { - fs.writeFile(fileName, JSON.stringify(data), (err) => { + fs.writeFile(configPath + fileName, JSON.stringify(data), (err) => { if (err) { console.log("Error when saving to json.") } -- 2.43.0