Skip to content

Commit

Permalink
fix #102 and #103
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Oct 2, 2023
1 parent eda30bc commit 455e6fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/backend/backendHelpers/toggleTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ export async function toggleTheme(
const { localThemeList } = python.globalState!.getPublicState();

// This is copied from the desktop codebase
// If we refactor the desktop version of this function (which we probably should) this should also be refactored
await python.generatePresetFromThemeNames(
selectedPreset.name,
localThemeList.filter((e) => e.enabled && !e.flags.includes(Flags.isPreset)).map((e) => e.name)
);
// Getting the new data for the preset
await python.getInstalledThemes();
}
13 changes: 11 additions & 2 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,17 @@ export async function scheduleCheckForUpdates() {

export async function changePreset(themeName: string, themeList: Theme[]) {
return new Promise(async (resolve) => {
// Disables all themes before enabling the preset
await Promise.all(themeList.filter((e) => e.enabled).map((e) => setThemeState(e.name, false)));
const { selectedPreset } = globalState!.getPublicState();

if (selectedPreset) {
// If you already have a preset enabled, since all currently enabled themes are part of that preset, you only need to disable it, not every theme
await setThemeState(selectedPreset!.name, false);
} else {
// On the contrary, if you have no preset, you still do have to disable the current themes and then enable the preset
await Promise.all(
themeList.filter((e) => e.enabled).map((e) => setThemeState(e.name, false))
);
}

if (themeName !== "None") {
await setThemeState(themeName, true);
Expand Down

0 comments on commit 455e6fd

Please sign in to comment.