Skip to content

refactor: app metadata#28113

Draft
shenlong-tanwen wants to merge 5 commits intomainfrom
refactor/app-metadata
Draft

refactor: app metadata#28113
shenlong-tanwen wants to merge 5 commits intomainfrom
refactor/app-metadata

Conversation

@shenlong-tanwen
Copy link
Copy Markdown
Member

Description

  • Moves from a flat key-value cache to a grouped store architecture
  • Theme mode and Log Level are migrated to the new entity

@shenlong-tanwen shenlong-tanwen force-pushed the refactor/app-metadata branch 3 times, most recently from fd98daa to 4fc0e42 Compare April 28, 2026 18:47
Comment thread mobile/lib/domain/models/metadata_key.dart Outdated
Comment thread mobile/lib/domain/models/metadata_key.dart Outdated
final MetadataDomain domain;
final String name;
final T defaultValue;
final List<T>? enumValues;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need enumValues?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values on the enum classes cannot be accessed dynamically so we need a way to store the list of possible values for each enum metadata so we can deserialise it from the reoo

Comment thread mobile/lib/domain/services/log.service.dart
Comment on lines +67 to +74
final enumValues = key.enumValues;
if (enumValues != null) {
return enumValues.where((v) => (v as Enum).name == raw).firstOrNull ?? key.defaultValue;
}
return switch (key.defaultValue) {
DateTime() => (DateTime.tryParse(raw) ?? key.defaultValue) as T,
_ => throw ArgumentError('Unsupported metadata value type: ${key.defaultValue.runtimeType}'),
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, I think the enum and type handling here is a bit weird. I wonder if there's a nicer way to do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to drop the generic handling and let every enum key provide it's own encoder and decoder. We could also have a list of predefined codecs for the primitives. I initially had it that way but then each Metadata key definition got lengthier, so resorted to this generic implementation. Moving to a per-key codec would also let us drop the enumValues on the key as it is used during the decoding logic to get the enum value from the string

Comment thread mobile/lib/infrastructure/repositories/metadata.repository.dart Outdated
Comment thread mobile/lib/infrastructure/repositories/metadata.repository.dart Outdated
Comment on lines +86 to +89
Stream<AppConfig> watchAppConfig() => _watchDomain(MetadataDomain.appConfig).map((_) => appConfig).distinct();

Stream<SystemConfig> watchSystemConfig() =>
_watchDomain(MetadataDomain.systemConfig).map((_) => systemConfig).distinct();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's weird to use map like this

Comment thread mobile/lib/utils/migration.dart Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants