]> Repos - mime-chat/commitdiff
add userData config path to helper functions
authorEnrique Hernandez <hernandeze2@xavier.edu>
Sat, 17 Apr 2021 16:57:22 +0000 (12:57 -0400)
committerEnrique Hernandez <hernandeze2@xavier.edu>
Sat, 17 Apr 2021 16:57:22 +0000 (12:57 -0400)
src/background/helpers.ts

index bd3d2792e700700f157fb7f092732d0e77f06add..f0074fb16999f8e5a58c376a3f31f6c39a825e71 100644 (file)
@@ -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.")
         }