@@ -162,8 +162,8 @@ const defaultSideEffectsTriggerId = settingId =>
162
162
/*****/
163
163
164
164
const state = {
165
- autoplayPlaylists : true ,
166
- autoplayVideos : true ,
165
+ enablePlaylistAutoplay : true ,
166
+ startVideosAutomatically : true ,
167
167
backendFallback : process . env . IS_ELECTRON ,
168
168
backendPreference : ! process . env . IS_ELECTRON ? 'invidious' : 'local' ,
169
169
barColor : false ,
@@ -178,7 +178,7 @@ const state = {
178
178
defaultProfile : MAIN_PROFILE_ID ,
179
179
defaultQuality : '720' ,
180
180
defaultSkipInterval : 5 ,
181
- defaultTheatreMode : false ,
181
+ defaultTheaterMode : false ,
182
182
defaultVideoFormat : 'dash' ,
183
183
disableSmoothScrolling : false ,
184
184
displayVideoPlayButton : true ,
@@ -218,7 +218,7 @@ const state = {
218
218
hideSubscriptionsLive : false ,
219
219
hideSubscriptionsCommunity : false ,
220
220
hideTrendingVideos : false ,
221
- hideUnsubscribeButton : false ,
221
+ hideSubscribeButton : false ,
222
222
hideUpcomingPremieres : false ,
223
223
hideVideoLikesAndDislikes : false ,
224
224
hideVideoViews : false ,
@@ -229,7 +229,7 @@ const state = {
229
229
landingPage : 'subscriptions' ,
230
230
listType : 'grid' ,
231
231
maxVideoPlaybackRate : 3 ,
232
- playNextVideo : false ,
232
+ enableAutoplay : false ,
233
233
proxyHostname : '127.0.0.1' ,
234
234
proxyPort : '9050' ,
235
235
proxyProtocol : 'socks5' ,
@@ -299,15 +299,13 @@ const state = {
299
299
useDeArrowTitles : false ,
300
300
}
301
301
302
- // NOTE: when an old setting's variable name is changed, place the new value here as the key
303
- // and keep the original key in the state object above. This preserves users' settings selections
304
- // even after these variable names are altered, and even in older versions of FreeTube.
305
- const aliasToOriginal = {
306
- defaultTheaterMode : 'defaultTheatreMode' ,
307
- enableAutoplay : 'playNextVideo' ,
308
- enablePlaylistAutoplay : 'autoplayPlaylists' ,
309
- hideSubscribeButton : 'hideUnsubscribeButton' ,
310
- startVideosAutomatically : 'autoplayVideos'
302
+ /* Mapping of older settings whose variable names have changed to their newer values */
303
+ const outdatedSettings = {
304
+ defaultTheatreMode : 'defaultTheaterMode' ,
305
+ playNextVideo : 'enableAutoplay' ,
306
+ autoplayPlaylists : 'enablePlaylistAutoplay' ,
307
+ hideUnsubscribeButton : 'hideSubscribeButton' ,
308
+ autoplayVideos : 'startVideosAutomatically'
311
309
}
312
310
313
311
const stateWithSideEffects = {
@@ -429,8 +427,7 @@ const customActions = {
429
427
Object . fromEntries ( ( await DBSettingHandlers . find ( ) ) . map ( ( { _id, value } ) => { return [ _id , value ] } ) ) )
430
428
)
431
429
432
- for ( const setting of userSettings ) {
433
- const [ _id , value ] = setting
430
+ const loadSetting = ( _id , value ) => {
434
431
if ( getters . settingHasSideEffects ( _id ) ) {
435
432
dispatch ( defaultSideEffectsTriggerId ( _id ) , value )
436
433
}
@@ -439,6 +436,24 @@ const customActions = {
439
436
commit ( defaultMutationId ( _id ) , value )
440
437
}
441
438
}
439
+
440
+ for ( const setting of userSettings ) {
441
+ const [ _id , value ] = setting
442
+ loadSetting ( _id , value )
443
+ }
444
+
445
+ // Apply existing values of outdated setting variables in the DB to their newer equivalents,
446
+ // then delete those older settings
447
+ for ( const outdatedSetting of Object . keys ( outdatedSettings ) ) {
448
+ const outdatedSettingInDB = userSettings . find ( ( setting ) => setting [ 0 ] === outdatedSetting )
449
+ if ( ! outdatedSettingInDB ) {
450
+ return
451
+ }
452
+ const newSetting = outdatedSettings [ outdatedSetting ]
453
+ const oldValue = outdatedSettingInDB [ 1 ]
454
+ loadSetting ( newSetting , oldValue )
455
+ await DBSettingHandlers . delete ( outdatedSetting )
456
+ }
442
457
} catch ( errMessage ) {
443
458
console . error ( errMessage )
444
459
}
@@ -556,20 +571,6 @@ for (const settingId of Object.keys(state)) {
556
571
buildSettingsStoreMethods ( settingId )
557
572
}
558
573
559
- // point alias keys to their original values
560
- for ( const alias of Object . keys ( aliasToOriginal ) ) {
561
- const aliasFor = aliasToOriginal [ alias ]
562
- const originalGetter = getters [ defaultGetterId ( aliasFor ) ]
563
- const originalMutation = mutations [ defaultMutationId ( aliasFor ) ]
564
- const originalTrigger = actions [ defaultSideEffectsTriggerId ( aliasFor ) ]
565
- const originalAction = actions [ defaultUpdaterId ( aliasFor ) ]
566
-
567
- if ( originalGetter ) getters [ defaultGetterId ( alias ) ] = originalGetter
568
- if ( originalMutation ) mutations [ defaultMutationId ( alias ) ] = originalMutation
569
- if ( originalTrigger ) actions [ defaultSideEffectsTriggerId ( alias ) ] = originalTrigger
570
- if ( originalAction ) actions [ defaultUpdaterId ( alias ) ] = originalAction
571
- }
572
-
573
574
function buildSettingsStoreMethods ( settingId ) {
574
575
const getterId = defaultGetterId ( settingId )
575
576
const mutationId = defaultMutationId ( settingId )
0 commit comments