fix: check if user is entitled to theme before activating it (#867)

This commit is contained in:
Aman Harwara
2022-02-17 01:13:05 +05:30
committed by GitHub
parent 1983b94a49
commit ca3112dcaf

View File

@@ -69,26 +69,51 @@ export class ThemeManager extends ApplicationService {
async onAppEvent(event: ApplicationEvent) { async onAppEvent(event: ApplicationEvent) {
super.onAppEvent(event); super.onAppEvent(event);
if (event === ApplicationEvent.SignedOut) { switch (event) {
case ApplicationEvent.SignedOut: {
this.deactivateAllThemes(); this.deactivateAllThemes();
this.activeThemes = []; this.activeThemes = [];
this.application?.removeValue( this.application?.removeValue(
CACHED_THEMES_KEY, CACHED_THEMES_KEY,
StorageValueModes.Nonwrapped StorageValueModes.Nonwrapped
); );
} else if (event === ApplicationEvent.StorageReady) { break;
}
case ApplicationEvent.StorageReady: {
await this.activateCachedThemes(); await this.activateCachedThemes();
} else if (event === ApplicationEvent.FeaturesUpdated) { break;
}
case ApplicationEvent.FeaturesUpdated: {
this.reloadThemeStatus(); this.reloadThemeStatus();
} else if (event === ApplicationEvent.Launched) { break;
}
case ApplicationEvent.Launched: {
window window
.matchMedia('(prefers-color-scheme: dark)') .matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', this.colorSchemeEventHandler); .addEventListener('change', this.colorSchemeEventHandler);
} else if (event === ApplicationEvent.PreferencesChanged) { break;
}
case ApplicationEvent.PreferencesChanged: {
const prefersDarkColorScheme = window.matchMedia( const prefersDarkColorScheme = window.matchMedia(
'(prefers-color-scheme: dark)' '(prefers-color-scheme: dark)'
); );
this.setThemeAsPerColorScheme(prefersDarkColorScheme.matches); this.setThemeAsPerColorScheme(prefersDarkColorScheme.matches);
break;
}
case ApplicationEvent.LocalDataLoaded: {
const themes = this.application.getDisplayableItems(
ContentType.Theme
) as SNTheme[];
themes.forEach((theme) => {
if (
theme.active &&
this.application.getFeatureStatus(theme.identifier) !==
FeatureStatus.Entitled
) {
this.application.toggleTheme(theme);
}
});
}
} }
} }
@@ -181,6 +206,12 @@ export class ThemeManager extends ApplicationService {
if (this.activeThemes.find((uuid) => uuid === theme.uuid)) { if (this.activeThemes.find((uuid) => uuid === theme.uuid)) {
return; return;
} }
if (
this.application.getFeatureStatus(theme.identifier) !==
FeatureStatus.Entitled
) {
return;
}
this.activeThemes.push(theme.uuid); this.activeThemes.push(theme.uuid);
const url = this.application.componentManager.urlForComponent(theme); const url = this.application.componentManager.urlForComponent(theme);
if (!url) { if (!url) {