File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import * as path from "path";
33import * as fs from "fs" ;
44
55import { DEFAULT_SETTINGS , accessSync } from "Utils/Main" ;
6+ import { logger } from "./Logger" ;
67
78/**
89 * This class has dual initialization: in main process and renderer process
@@ -50,7 +51,16 @@ export class Storage {
5051 private readSync = ( ) : Types . SettingsInterface => {
5152 const content = fs . readFileSync ( this . filePath ) . toString ( ) ;
5253
53- return JSON . parse ( content ) ;
54+ let settings : Types . SettingsInterface ;
55+ try {
56+ settings = JSON . parse ( content ) ;
57+ } catch ( error ) {
58+ logger . error ( "Parse settings.json file error: " , error ) ;
59+ logger . warn ( "Apply default settings instead file settings." ) ;
60+ settings = DEFAULT_SETTINGS ;
61+ }
62+
63+ return settings ;
5464 } ;
5565 private writeSync = ( settings : Types . SettingsInterface ) : void => {
5666 fs . writeFileSync ( this . filePath , JSON . stringify ( settings , null , 2 ) ) ;
You can’t perform that action at this time.
0 commit comments