@@ -55,20 +55,10 @@ public static ToolStripItem[] GetMenuItems()
5555 } ;
5656 }
5757
58- public static void AddThemeToHistory ( string themeId , bool clearHistory = false )
58+ public static void AddThemeToHistory ( string themeId )
5959 {
60- List < string > shuffleHistory ;
61-
62- if ( ! clearHistory )
63- {
64- shuffleHistory = JsonConfig . settings . shuffleHistory ? . ToList ( ) ?? new List < string > ( ) ;
65- shuffleHistory . Remove ( themeId ) ;
66- }
67- else
68- {
69- shuffleHistory = new List < string > ( ) ;
70- }
71-
60+ List < string > shuffleHistory = JsonConfig . settings . shuffleHistory ? . ToList ( ) ?? new List < string > ( ) ;
61+ shuffleHistory . Remove ( themeId ) ;
7262 shuffleHistory . Add ( themeId ) ;
7363 JsonConfig . settings . shuffleHistory = shuffleHistory . ToArray ( ) ;
7464 JsonConfig . settings . lastShuffleTime = DateTime . Now . ToString ( CultureInfo . InvariantCulture ) ;
@@ -147,7 +137,7 @@ public static void AddThemeToHistory(string themeId, bool clearHistory = false)
147137 return nextUpdateTime ? . AddTicks ( 1 ) ;
148138 }
149139
150- private static ThemeConfig GetNextTheme ( )
140+ private static ThemeConfig GetNextTheme ( string lastThemeId )
151141 {
152142 List < string > shuffleHistory = JsonConfig . settings . shuffleHistory ? . ToList ( ) ?? new List < string > ( ) ;
153143 ThemeConfig [ ] themeChoices = GetThemeChoices ( ) . Where (
@@ -162,15 +152,16 @@ private static ThemeConfig GetNextTheme()
162152 {
163153 themeChoices = GetThemeChoices ( ) . ToArray ( ) ;
164154 nextTheme = themeChoices [ rng . Next ( themeChoices . Length ) ] ;
165- string lastThemeId = shuffleHistory . LastOrDefault ( ) ;
155+ lastThemeId = lastThemeId ?? shuffleHistory . LastOrDefault ( ) ;
156+ Array . Clear ( JsonConfig . settings . shuffleHistory ) ;
166157
167158 while ( ( themeChoices . Length > 1 ) && ( nextTheme . themeId == lastThemeId ) )
168159 {
169160 nextTheme = themeChoices [ rng . Next ( themeChoices . Length ) ] ;
170161 }
171162 }
172163
173- AddThemeToHistory ( nextTheme . themeId , themeChoices . Length == 0 ) ;
164+ AddThemeToHistory ( nextTheme . themeId ) ;
174165 return nextTheme ;
175166 }
176167
@@ -196,19 +187,19 @@ private static void ShuffleWallpaper()
196187 {
197188 if ( JsonConfig . settings . activeThemes [ 0 ] != null )
198189 {
199- JsonConfig . settings . activeThemes [ 0 ] = GetNextTheme ( ) . themeId ;
190+ JsonConfig . settings . activeThemes [ 0 ] = GetNextTheme ( JsonConfig . settings . activeThemes [ 0 ] ) . themeId ;
200191 }
201192 else
202193 {
203194 for ( int i = 1 ; i < JsonConfig . settings . activeThemes . Length ; i ++ )
204195 {
205- JsonConfig . settings . activeThemes [ i ] = GetNextTheme ( ) . themeId ;
196+ JsonConfig . settings . activeThemes [ i ] = GetNextTheme ( JsonConfig . settings . activeThemes [ i ] ) . themeId ;
206197 }
207198 }
208199
209200 if ( JsonConfig . settings . lockScreenTheme != null )
210201 {
211- JsonConfig . settings . lockScreenTheme = GetNextTheme ( ) . themeId ;
202+ JsonConfig . settings . lockScreenTheme = GetNextTheme ( JsonConfig . settings . lockScreenTheme ) . themeId ;
212203 }
213204 }
214205
0 commit comments