@@ -19,20 +19,21 @@ export interface ConnectionConfig {
1919
2020export interface GeneralConfig {
2121 useNotifications : boolean
22+ disableWipNotifications : boolean
2223 darkMode : boolean
2324}
2425
2526interface ConfigContext {
2627 config : Config
2728 removeConfig : ( ) => void
28- updateConfig : ( newConfig : Config ) => void
2929 updateConnectionConfig : ( newConnectionConfig : ConnectionConfig ) => void
3030 updateGeneralConfig : ( newGeneralConfig : GeneralConfig ) => void
3131}
3232
3333const defaultConfig : Config = {
3434 generalConfig : {
3535 useNotifications : true ,
36+ disableWipNotifications : true ,
3637 darkMode : remote . nativeTheme . shouldUseDarkColors ,
3738 } ,
3839}
@@ -70,13 +71,30 @@ const configPreviousVersion = (oldKey: string, newKey: string): Config | null =>
7071 return null
7172}
7273
73- const configFromPreviousVersionOrDefault = ( ) : Config | null => {
74+ const configFromPreviousVersionOrDefault = ( ) : Config => {
7475 return configPreviousVersion ( 'config' , 'config.v3' ) || configPreviousVersion ( 'config.v2' , 'config.v3' ) || defaultConfig
7576}
7677
77- export const ConfigProvider = ( { ... props } ) => {
78+ const loadConfig = ( ) : Config => {
7879 const localStorageValue = window . localStorage . getItem ( 'config.v3' )
79- const [ config , setConfig ] = React . useState < Config > ( localStorageValue ? JSON . parse ( localStorageValue ) : configFromPreviousVersionOrDefault ( ) )
80+
81+ if ( localStorageValue ) {
82+ const savedConfig = JSON . parse ( localStorageValue )
83+
84+ return {
85+ connectionConfig : savedConfig . connectionConfig ,
86+ generalConfig : {
87+ ...defaultConfig . generalConfig ,
88+ ...savedConfig . generalConfig ,
89+ } ,
90+ }
91+ }
92+
93+ return configFromPreviousVersionOrDefault ( )
94+ }
95+
96+ export const ConfigProvider = ( { ...props } ) => {
97+ const [ config , setConfig ] = React . useState < Config > ( loadConfig ( ) )
8098
8199 const removeConfig = ( ) => {
82100 setConfig ( defaultConfig )
@@ -104,5 +122,5 @@ export const ConfigProvider = ({ ...props }) => {
104122 updateConfig ( newConfig )
105123 }
106124
107- return < Context . Provider value = { { config, updateConfig , removeConfig, updateConnectionConfig, updateGeneralConfig } } { ...props } />
125+ return < Context . Provider value = { { config, removeConfig, updateConnectionConfig, updateGeneralConfig } } { ...props } />
108126}
0 commit comments