@@ -953,7 +953,15 @@ function populate_profile_pulldown() {
953
953
}
954
954
955
955
function get_current_profile ( ) {
956
- return STATE [ "profiles" ] [ STATE [ "current_profile" ] ] ;
956
+ let current_profile = STATE [ "current_profile" ] ;
957
+ if ( ! STATE [ "profiles" ] . hasOwnProperty ( current_profile ) ) {
958
+ // If we're in an illegal state where we are stuck as a deleted
959
+ // profile, fall back to being the guest profile.
960
+ current_profile = _GUEST_USER_ID ;
961
+ STATE [ "current_profile" ] = current_profile ;
962
+ set_current_profile ( STATE [ current_profile ] ) ;
963
+ }
964
+ return STATE [ "profiles" ] [ current_profile ] ;
957
965
}
958
966
959
967
function select_new_profile ( elem ) {
@@ -965,9 +973,10 @@ function select_new_profile(elem) {
965
973
function open_profile_adder ( ) {
966
974
console . log ( "Creating new profile" ) ;
967
975
976
+ toggle_profile_visibility ( ) ;
977
+ toggle_profile_settings_visibility ( false ) ;
968
978
clear_profile_dialog ( ) ;
969
979
let profile_container = document . getElementById ( "profile-info-container" ) ;
970
- profile_container . classList . add ( "visible" ) ;
971
980
972
981
for ( var elem of profile_container . querySelectorAll ( "button.add-button" ) ) {
973
982
elem . classList . add ( "visible" ) ;
@@ -977,14 +986,11 @@ function open_profile_adder() {
977
986
978
987
let target_number_elem = document . getElementById ( "target_number_setting" ) ;
979
988
target_number_elem . value = _DEFAULT_TARGET_NUMBER ;
980
-
981
- toggle_profile_visibility ( ) ;
982
989
}
983
990
984
991
function close_profile_adder ( ) {
985
992
console . log ( "Closing profile adder" ) ;
986
- let profile_container = document . getElementById ( "profile-info-container" ) ;
987
- profile_container . classList . remove ( "visible" ) ;
993
+ toggle_profile_settings_visibility ( ) ;
988
994
clear_profile_dialog ( ) ;
989
995
}
990
996
@@ -1106,7 +1112,6 @@ function populate_profile_settings() {
1106
1112
const is_guest = ( profile . id === _GUEST_USER_ID ) ;
1107
1113
clear_profile_dialog ( ) ;
1108
1114
let profile_dialog = document . getElementById ( "profile-info-container" ) ;
1109
- profile_dialog . classList . add ( "visible" ) ;
1110
1115
for ( let elem of profile_dialog . querySelectorAll ( "button.settings-button" ) ) {
1111
1116
elem . classList . add ( "visible" ) ;
1112
1117
}
@@ -1189,6 +1194,8 @@ function delete_profile() {
1189
1194
alert ( "Deleting the guest user is not allowed." ) ;
1190
1195
return ;
1191
1196
} else if ( confirm ( "Are you sure you want to delete the profile " + STATE . profiles [ profile_id ] . name + "?" ) ) {
1197
+ // Set the current profile to the guest profile
1198
+ set_current_profile_by_id ( _GUEST_USER_ID ) ;
1192
1199
delete STATE . profiles [ profile_id ] ;
1193
1200
}
1194
1201
@@ -1235,6 +1242,12 @@ function set_chord_display_mode(chord_mode) {
1235
1242
}
1236
1243
}
1237
1244
1245
+
1246
+ function set_current_profile_by_id ( profile_id ) {
1247
+ let profile = STATE [ "profiles" ] [ profile_id ] ;
1248
+ return set_current_profile ( profile ) ;
1249
+ }
1250
+
1238
1251
function set_current_profile ( profile ) {
1239
1252
if ( profile . id !== get_current_profile ( ) . id ) {
1240
1253
// Reset the stats and retrieve any existing sessions
@@ -1288,11 +1301,16 @@ function toggle_stats_history_visibility() {
1288
1301
toggle_visibility ( document . getElementById ( "stats-history-container" ) ) ;
1289
1302
}
1290
1303
1291
- function toggle_profile_settings_visibility ( ) {
1304
+ function toggle_profile_settings_visibility ( populate = true ) {
1292
1305
const ibox = document . getElementById ( "profile-info-container" ) ;
1293
- populate_profile_settings ( ) ;
1294
-
1295
- toggle_visibility ( ibox ) ;
1306
+ if ( ibox . classList . contains ( "visible" ) ) {
1307
+ ibox . classList . remove ( "visible" ) ;
1308
+ } else {
1309
+ if ( populate ) {
1310
+ populate_profile_settings ( ) ;
1311
+ }
1312
+ ibox . classList . add ( "visible" ) ;
1313
+ }
1296
1314
}
1297
1315
1298
1316
function toggle_theme_mode ( ) {
0 commit comments