add userData config path to helper functions
This commit is contained in:
parent
451e0380ac
commit
aab9ae136d
1 changed files with 5 additions and 3 deletions
|
|
@ -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.")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue