Safeguarding against empty default profile
This commit is contained in:
parent
da8256f002
commit
af11eb9010
2 changed files with 12 additions and 1 deletions
|
|
@ -221,7 +221,7 @@ export class App {
|
||||||
const devPrefSet = localStorage.getItem('device_preference_set') || 'default'
|
const devPrefSet = localStorage.getItem('device_preference_set') || 'default'
|
||||||
const userData = localStorage.getItem('user') || '{"default": {}}'
|
const userData = localStorage.getItem('user') || '{"default": {}}'
|
||||||
const user = JSON.parse(userData)
|
const user = JSON.parse(userData)
|
||||||
return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet])
|
return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet] || {})
|
||||||
}// }}}
|
}// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,7 @@ export class N2PreferenceSet extends CustomHTMLElement {
|
||||||
super(true)
|
super(true)
|
||||||
this.name = name
|
this.name = name
|
||||||
this.data = data
|
this.data = data
|
||||||
|
this.validateDefaultProfile()
|
||||||
this.render()
|
this.render()
|
||||||
|
|
||||||
// Enable the save button when settings are modified.
|
// Enable the save button when settings are modified.
|
||||||
|
|
@ -248,6 +249,16 @@ export class N2PreferenceSet extends CustomHTMLElement {
|
||||||
this.elName.addEventListener('click', () => this.updateName())
|
this.elName.addEventListener('click', () => this.updateName())
|
||||||
this.elDelete.addEventListener('click', () => this.deleteSet())
|
this.elDelete.addEventListener('click', () => this.deleteSet())
|
||||||
}// }}}
|
}// }}}
|
||||||
|
validateDefaultProfile() {// {{{
|
||||||
|
if (!this.data.hasOwnProperty('default'))
|
||||||
|
this.data.default = {}
|
||||||
|
|
||||||
|
if (!this.data.default.hasOwnProperty('DownloadFiles'))
|
||||||
|
this.data.default.DownloadFiles = false
|
||||||
|
|
||||||
|
if (!this.data.default.hasOwnProperty('DownloadImages'))
|
||||||
|
this.data.default.DownloadImages = false
|
||||||
|
}// }}}
|
||||||
updateName() {// {{{
|
updateName() {// {{{
|
||||||
if (this.name == 'default') {
|
if (this.name == 'default') {
|
||||||
alert('Can not change name of the default profile.')
|
alert('Can not change name of the default profile.')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue