fix: Fixes issue where lock screen would not use previously active theme (#2372)
This commit is contained in:
@@ -6,11 +6,7 @@ import {
|
||||
NoteType,
|
||||
UIFeatureDescriptionTypes,
|
||||
} from '@standardnotes/features'
|
||||
import {
|
||||
isUIFeatureAnIframeFeature,
|
||||
isComponentOrFeatureDescriptionAComponent,
|
||||
isComponentOrFeatureDescriptionAFeatureDescription,
|
||||
} from './TypeGuards'
|
||||
import { isUIFeatureAnIframeFeature, isItemBasedFeature, isNativeFeature } from './TypeGuards'
|
||||
import { UIFeature } from './UIFeature'
|
||||
import { ComponentInterface } from '../../Syncable/Component'
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
@@ -45,7 +41,7 @@ describe('TypeGuards', () => {
|
||||
uuid: 'abc-123',
|
||||
} as ComponentInterface
|
||||
|
||||
expect(isComponentOrFeatureDescriptionAComponent(x)).toBe(true)
|
||||
expect(isItemBasedFeature(x)).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false if feature description is not a component', () => {
|
||||
@@ -53,17 +49,17 @@ describe('TypeGuards', () => {
|
||||
note_type: NoteType.Super,
|
||||
} as jest.Mocked<EditorFeatureDescription>
|
||||
|
||||
expect(isComponentOrFeatureDescriptionAComponent(x)).toBe(false)
|
||||
expect(isItemBasedFeature(x)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isComponentOrFeatureDescriptionAFeatureDescription', () => {
|
||||
describe('isNativeFeature', () => {
|
||||
it('should return true if x is a feature description', () => {
|
||||
const x: AnyFeatureDescription = {
|
||||
content_type: 'TestContentType',
|
||||
} as AnyFeatureDescription
|
||||
|
||||
expect(isComponentOrFeatureDescriptionAFeatureDescription(x)).toBe(true)
|
||||
expect(isNativeFeature(x)).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false if x is a component', () => {
|
||||
@@ -71,7 +67,7 @@ describe('TypeGuards', () => {
|
||||
uuid: 'abc-123',
|
||||
} as ComponentInterface
|
||||
|
||||
expect(isComponentOrFeatureDescriptionAFeatureDescription(x)).toBe(false)
|
||||
expect(isNativeFeature(x)).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,14 +14,10 @@ export function isUIFeatureAnIframeFeature(
|
||||
return isIframeComponentFeatureDescription(x.featureDescription)
|
||||
}
|
||||
|
||||
export function isComponentOrFeatureDescriptionAComponent(
|
||||
x: ComponentInterface | UIFeatureDescriptionTypes,
|
||||
): x is ComponentInterface {
|
||||
export function isItemBasedFeature(x: ComponentInterface | UIFeatureDescriptionTypes): x is ComponentInterface {
|
||||
return 'uuid' in x
|
||||
}
|
||||
|
||||
export function isComponentOrFeatureDescriptionAFeatureDescription(
|
||||
x: ComponentInterface | AnyFeatureDescription,
|
||||
): x is AnyFeatureDescription {
|
||||
export function isNativeFeature(x: ComponentInterface | AnyFeatureDescription): x is AnyFeatureDescription {
|
||||
return !('uuid' in x)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
ComponentArea,
|
||||
ComponentPermission,
|
||||
EditorFeatureDescription,
|
||||
FeatureIdentifier,
|
||||
NativeFeatureIdentifier,
|
||||
NoteType,
|
||||
ThemeDockIcon,
|
||||
UIFeatureDescriptionTypes,
|
||||
@@ -12,29 +12,27 @@ import {
|
||||
} from '@standardnotes/features'
|
||||
import { ComponentInterface } from '../../Syncable/Component/ComponentInterface'
|
||||
import { isTheme } from '../../Syncable/Theme'
|
||||
import {
|
||||
isComponentOrFeatureDescriptionAComponent,
|
||||
isComponentOrFeatureDescriptionAFeatureDescription,
|
||||
} from './TypeGuards'
|
||||
import { isItemBasedFeature, isNativeFeature } from './TypeGuards'
|
||||
import { UIFeatureInterface } from './UIFeatureInterface'
|
||||
import { Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeatureInterface<F> {
|
||||
constructor(public readonly item: ComponentInterface | F) {}
|
||||
|
||||
get isComponent(): boolean {
|
||||
return isComponentOrFeatureDescriptionAComponent(this.item)
|
||||
return isItemBasedFeature(this.item)
|
||||
}
|
||||
|
||||
get isFeatureDescription(): boolean {
|
||||
return isComponentOrFeatureDescriptionAFeatureDescription(this.item)
|
||||
return isNativeFeature(this.item)
|
||||
}
|
||||
|
||||
get isThemeComponent(): boolean {
|
||||
return isComponentOrFeatureDescriptionAComponent(this.item) && isTheme(this.item)
|
||||
return isItemBasedFeature(this.item) && isTheme(this.item)
|
||||
}
|
||||
|
||||
get asComponent(): ComponentInterface {
|
||||
if (isComponentOrFeatureDescriptionAComponent(this.item)) {
|
||||
if (isItemBasedFeature(this.item)) {
|
||||
return this.item
|
||||
}
|
||||
|
||||
@@ -42,29 +40,30 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get asFeatureDescription(): F {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item)) {
|
||||
return this.item
|
||||
}
|
||||
|
||||
throw new Error('Cannot cast item to feature description')
|
||||
}
|
||||
|
||||
get uniqueIdentifier(): string {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
return this.item.identifier
|
||||
get uniqueIdentifier(): NativeFeatureIdentifier | Uuid {
|
||||
if (isNativeFeature(this.item)) {
|
||||
const nativeFeature = NativeFeatureIdentifier.create(this.item.identifier)
|
||||
return nativeFeature.getValue()
|
||||
} else {
|
||||
return this.item.uuid
|
||||
return Uuid.create(this.item.uuid).getValue()
|
||||
}
|
||||
}
|
||||
|
||||
get featureIdentifier(): FeatureIdentifier {
|
||||
get featureIdentifier(): string {
|
||||
return this.item.identifier
|
||||
}
|
||||
|
||||
get noteType(): NoteType {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item) && isEditorFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item) && isEditorFeatureDescription(this.item)) {
|
||||
return this.item.note_type ?? NoteType.Unknown
|
||||
} else if (isComponentOrFeatureDescriptionAComponent(this.item)) {
|
||||
} else if (isItemBasedFeature(this.item)) {
|
||||
return this.item.noteType
|
||||
}
|
||||
|
||||
@@ -72,12 +71,9 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get fileType(): EditorFeatureDescription['file_type'] {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item) && isEditorFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item) && isEditorFeatureDescription(this.item)) {
|
||||
return this.item.file_type
|
||||
} else if (
|
||||
isComponentOrFeatureDescriptionAComponent(this.item) &&
|
||||
isEditorFeatureDescription(this.item.package_info)
|
||||
) {
|
||||
} else if (isItemBasedFeature(this.item) && isEditorFeatureDescription(this.item.package_info)) {
|
||||
return this.item.package_info?.file_type ?? 'txt'
|
||||
}
|
||||
|
||||
@@ -85,7 +81,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get displayName(): string {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item)) {
|
||||
return this.item.name ?? ''
|
||||
} else {
|
||||
return this.item.displayName
|
||||
@@ -93,7 +89,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get description(): string {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item)) {
|
||||
return this.item.description ?? ''
|
||||
} else {
|
||||
return this.item.package_info.description ?? ''
|
||||
@@ -101,7 +97,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get deprecationMessage(): string | undefined {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item)) {
|
||||
return this.item.deprecation_message
|
||||
} else {
|
||||
return this.item.deprecationMessage
|
||||
@@ -109,7 +105,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get expirationDate(): Date | undefined {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item)) {
|
||||
return this.item.expires_at ? new Date(this.item.expires_at) : undefined
|
||||
} else {
|
||||
return this.item.valid_until
|
||||
@@ -117,7 +113,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get featureDescription(): F {
|
||||
if (isComponentOrFeatureDescriptionAFeatureDescription(this.item)) {
|
||||
if (isNativeFeature(this.item)) {
|
||||
return this.item
|
||||
} else {
|
||||
return this.item.package_info as F
|
||||
@@ -125,12 +121,9 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get acquiredPermissions(): ComponentPermission[] {
|
||||
if (
|
||||
isComponentOrFeatureDescriptionAFeatureDescription(this.item) &&
|
||||
isIframeComponentFeatureDescription(this.item)
|
||||
) {
|
||||
if (isNativeFeature(this.item) && isIframeComponentFeatureDescription(this.item)) {
|
||||
return this.item.component_permissions ?? []
|
||||
} else if (isComponentOrFeatureDescriptionAComponent(this.item)) {
|
||||
} else if (isItemBasedFeature(this.item)) {
|
||||
return this.item.permissions
|
||||
}
|
||||
|
||||
@@ -146,7 +139,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get layerable(): boolean {
|
||||
if (isComponentOrFeatureDescriptionAComponent(this.item) && isTheme(this.item)) {
|
||||
if (isItemBasedFeature(this.item) && isTheme(this.item)) {
|
||||
return this.item.layerable
|
||||
} else if (isThemeFeatureDescription(this.asFeatureDescription)) {
|
||||
return this.asFeatureDescription.layerable ?? false
|
||||
@@ -156,7 +149,7 @@ export class UIFeature<F extends UIFeatureDescriptionTypes> implements UIFeature
|
||||
}
|
||||
|
||||
get dockIcon(): ThemeDockIcon | undefined {
|
||||
if (isComponentOrFeatureDescriptionAComponent(this.item) && isTheme(this.item)) {
|
||||
if (isItemBasedFeature(this.item) && isTheme(this.item)) {
|
||||
return this.item.package_info.dock_icon
|
||||
} else if (isThemeFeatureDescription(this.asFeatureDescription)) {
|
||||
return this.asFeatureDescription.dock_icon
|
||||
|
||||
@@ -2,12 +2,13 @@ import {
|
||||
ComponentArea,
|
||||
ComponentPermission,
|
||||
EditorFeatureDescription,
|
||||
FeatureIdentifier,
|
||||
NativeFeatureIdentifier,
|
||||
NoteType,
|
||||
ThemeDockIcon,
|
||||
UIFeatureDescriptionTypes,
|
||||
} from '@standardnotes/features'
|
||||
import { ComponentInterface } from '../../Syncable/Component'
|
||||
import { Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export interface UIFeatureInterface<F extends UIFeatureDescriptionTypes> {
|
||||
item: ComponentInterface | F
|
||||
@@ -16,8 +17,8 @@ export interface UIFeatureInterface<F extends UIFeatureDescriptionTypes> {
|
||||
get isThemeComponent(): boolean
|
||||
get asComponent(): ComponentInterface
|
||||
get asFeatureDescription(): F
|
||||
get uniqueIdentifier(): string
|
||||
get featureIdentifier(): FeatureIdentifier
|
||||
get uniqueIdentifier(): NativeFeatureIdentifier | Uuid
|
||||
get featureIdentifier(): string
|
||||
get noteType(): NoteType
|
||||
get fileType(): EditorFeatureDescription['file_type']
|
||||
get displayName(): string
|
||||
|
||||
Reference in New Issue
Block a user