()
| 191 | } |
| 192 | |
| 193 | export async function randomizeTheme(): Promise<void> { |
| 194 | if (themesList.length === 0) { |
| 195 | await changeThemeList(); |
| 196 | if (themesList.length === 0) return; |
| 197 | } |
| 198 | |
| 199 | let filter = (_: string): boolean => true; |
| 200 | if (Config.randomTheme === "auto") { |
| 201 | filter = prefersColorSchemeDark() ? isColorDark : isColorLight; |
| 202 | } |
| 203 | |
| 204 | let nextTheme = null; |
| 205 | do { |
| 206 | randomTheme = themesList[randomThemeIndex] as ThemeIdentifier; |
| 207 | nextTheme = themes[themesList[randomThemeIndex] as ThemeName]; |
| 208 | randomThemeIndex++; |
| 209 | if (randomThemeIndex >= themesList.length) { |
| 210 | Arrays.shuffle(themesList); |
| 211 | randomThemeIndex = 0; |
| 212 | } |
| 213 | } while (!filter(nextTheme.bg)); |
| 214 | |
| 215 | let colorsOverride: CustomThemeColors | undefined; |
| 216 | |
| 217 | if (Config.randomTheme === "custom") { |
| 218 | const theme = CustomThemes.__nonReactive.getCustomTheme( |
| 219 | randomTheme as string, |
| 220 | ); |
| 221 | colorsOverride = theme?.colors; |
| 222 | randomTheme = "custom"; |
| 223 | } |
| 224 | |
| 225 | setConfig("customTheme", false, { |
| 226 | nosave: true, |
| 227 | }); |
| 228 | await apply(randomTheme, colorsOverride); |
| 229 | |
| 230 | if (randomThemeIndex >= themesList.length) { |
| 231 | let name = randomTheme.replace(/_/g, " "); |
| 232 | if (Config.randomTheme === "custom") { |
| 233 | name = ( |
| 234 | CustomThemes.__nonReactive.getCustomTheme(randomTheme as string) |
| 235 | ?.name ?? "custom" |
| 236 | ).replace(/_/g, " "); |
| 237 | } |
| 238 | showNoticeNotification(name); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | async function clearRandom(): Promise<void> { |
| 243 | if (randomTheme === null) return; |
no test coverage detected