fix: dark mode not working in editors (#1773)

This commit is contained in:
Aman Harwara
2022-10-10 21:47:57 +05:30
committed by GitHub
parent dcb8024deb
commit 27d2c95b5b
30 changed files with 127 additions and 190 deletions

View File

@@ -44,6 +44,7 @@ import {
SetOfflineFeaturesFunctionResponse,
StorageKey,
} from '@standardnotes/services'
import { FeatureIdentifier } from '@standardnotes/features'
type GetOfflineSubscriptionDetailsResponse = OfflineSubscriptionEntitlements | ClientDisplayableError
@@ -145,7 +146,10 @@ export class SNFeaturesService
override async handleApplicationStage(stage: ApplicationStage): Promise<void> {
await super.handleApplicationStage(stage)
if (stage === ApplicationStage.FullSyncCompleted_13) {
void this.addDarkTheme()
if (!this.hasOnlineSubscription()) {
const offlineRepo = this.getOfflineRepo()
if (offlineRepo) {
@@ -155,6 +159,14 @@ export class SNFeaturesService
}
}
private async addDarkTheme() {
const darkThemeFeature = FeaturesImports.FindNativeFeature(FeatureIdentifier.DarkTheme)
if (darkThemeFeature) {
await this.mapRemoteNativeFeaturesToItems([darkThemeFeature])
}
}
public enableExperimentalFeature(identifier: FeaturesImports.FeatureIdentifier): void {
const feature = this.getUserFeature(identifier)
if (!feature) {
@@ -366,7 +378,7 @@ export class SNFeaturesService
if (!arraysEqual(this.roles, roles)) {
void this.notifyEvent(FeaturesEvent.UserRolesChanged)
}
await this.storageService.setValue(StorageKey.UserRoles, this.roles)
this.storageService.setValue(StorageKey.UserRoles, this.roles)
}
public async didDownloadFeatures(features: FeaturesImports.FeatureDescription[]): Promise<void> {
@@ -448,7 +460,15 @@ export class SNFeaturesService
return FeaturesImports.FindNativeFeature(featureId)?.deprecated === true
}
public isFreeFeature(featureId: FeaturesImports.FeatureIdentifier) {
return [FeatureIdentifier.DarkTheme].includes(featureId)
}
public getFeatureStatus(featureId: FeaturesImports.FeatureIdentifier): FeatureStatus {
if (this.isFreeFeature(featureId)) {
return FeatureStatus.Entitled
}
const isDeprecated = this.isFeatureDeprecated(featureId)
if (isDeprecated) {
if (this.hasPaidOnlineOrOfflineSubscription()) {
@@ -548,7 +568,9 @@ export class SNFeaturesService
let hasChanges = false
const now = new Date()
const expired = new Date(feature.expires_at || 0).getTime() < now.getTime()
const expired = this.isFreeFeature(feature.identifier)
? false
: new Date(feature.expires_at || 0).getTime() < now.getTime()
const existingItem = currentItems.find((item) => {
if (item.content.package_info) {