checking if snapshot exists

updating random theme list if its empty
closes #3248
This commit is contained in:
Miodec 2022-06-27 12:30:10 +02:00
parent f2d9d37b3e
commit fb539ddd19
2 changed files with 7 additions and 4 deletions

View file

@ -197,6 +197,7 @@ export function clearPreview(applyTheme = true): void {
let themesList: string[] = [];
async function changeThemeList(): Promise<void> {
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<void> {
randomThemeIndex = 0;
}
export function randomizeTheme(): void {
//! setting randomThemeIndex to 0 everytime randomizeTheme is called
export async function randomizeTheme(): Promise<void> {
if (themesList.length === 0) {
await changeThemeList();
if (themesList.length === 0) return;
}
const randomTheme = themesList[randomThemeIndex];
randomThemeIndex++;

View file

@ -2951,7 +2951,7 @@ export const defaultCommands: MonkeyTypes.CommandsGroup = {
id: "randomizeTheme",
display: "Next random theme",
icon: "fa-random",
exec: (): void => ThemeController.randomizeTheme(),
exec: (): Promise<void> => ThemeController.randomizeTheme(),
available: (): boolean => {
return Config.randomTheme !== "off";
},