diff --git a/frontend/src/ts/controllers/theme-controller.ts b/frontend/src/ts/controllers/theme-controller.ts index 4991e63e0..2866b2bc8 100644 --- a/frontend/src/ts/controllers/theme-controller.ts +++ b/frontend/src/ts/controllers/theme-controller.ts @@ -197,6 +197,7 @@ export function clearPreview(applyTheme = true): void { let themesList: string[] = []; async function changeThemeList(): Promise { + if (!DB.getSnapshot()) return; const themes = await Misc.getThemesList(); if (Config.randomTheme === "fav" && Config.favThemes.length > 0) { themesList = Config.favThemes; @@ -219,9 +220,11 @@ async function changeThemeList(): Promise { randomThemeIndex = 0; } -export function randomizeTheme(): void { - //! setting randomThemeIndex to 0 everytime randomizeTheme is called - +export async function randomizeTheme(): Promise { + if (themesList.length === 0) { + await changeThemeList(); + if (themesList.length === 0) return; + } const randomTheme = themesList[randomThemeIndex]; randomThemeIndex++; diff --git a/frontend/src/ts/elements/commandline-lists.ts b/frontend/src/ts/elements/commandline-lists.ts index 90db523b5..486f23b24 100644 --- a/frontend/src/ts/elements/commandline-lists.ts +++ b/frontend/src/ts/elements/commandline-lists.ts @@ -2951,7 +2951,7 @@ export const defaultCommands: MonkeyTypes.CommandsGroup = { id: "randomizeTheme", display: "Next random theme", icon: "fa-random", - exec: (): void => ThemeController.randomizeTheme(), + exec: (): Promise => ThemeController.randomizeTheme(), available: (): boolean => { return Config.randomTheme !== "off"; },