update property names of KeyCustomization

This commit is contained in:
Adam Velebil 2024-01-24 11:14:55 +01:00
parent 15212af086
commit 9c4e31ef46
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
7 changed files with 49 additions and 61 deletions

View File

@ -51,11 +51,10 @@ class KeyCustomizationManager {
return _customizations[serial]; return _customizations[serial];
} }
void set({required String serial, String? customName, Color? customColor}) { void set({required String serial, String? name, Color? color}) {
_log.debug( _log.debug('Setting key customization for $serial: $name, $color');
'Setting key customization for $serial: $customName, $customColor'); _customizations[serial] =
_customizations[serial] = KeyCustomization( KeyCustomization(serial: serial, name: name, color: color);
serial: serial, customName: customName, customColor: customColor);
} }
Future<void> write() async { Future<void> write() async {

View File

@ -26,8 +26,8 @@ part 'models.g.dart';
class KeyCustomization with _$KeyCustomization { class KeyCustomization with _$KeyCustomization {
factory KeyCustomization({ factory KeyCustomization({
required String serial, required String serial,
String? customName, String? name,
@_ColorConverter() Color? customColor, @_ColorConverter() Color? color,
}) = _KeyCustomization; }) = _KeyCustomization;
factory KeyCustomization.fromJson(Map<String, dynamic> json) => factory KeyCustomization.fromJson(Map<String, dynamic> json) =>

View File

@ -21,9 +21,9 @@ KeyCustomization _$KeyCustomizationFromJson(Map<String, dynamic> json) {
/// @nodoc /// @nodoc
mixin _$KeyCustomization { mixin _$KeyCustomization {
String get serial => throw _privateConstructorUsedError; String get serial => throw _privateConstructorUsedError;
String? get customName => throw _privateConstructorUsedError; String? get name => throw _privateConstructorUsedError;
@_ColorConverter() @_ColorConverter()
Color? get customColor => throw _privateConstructorUsedError; Color? get color => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError; Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
@ -37,10 +37,7 @@ abstract class $KeyCustomizationCopyWith<$Res> {
KeyCustomization value, $Res Function(KeyCustomization) then) = KeyCustomization value, $Res Function(KeyCustomization) then) =
_$KeyCustomizationCopyWithImpl<$Res, KeyCustomization>; _$KeyCustomizationCopyWithImpl<$Res, KeyCustomization>;
@useResult @useResult
$Res call( $Res call({String serial, String? name, @_ColorConverter() Color? color});
{String serial,
String? customName,
@_ColorConverter() Color? customColor});
} }
/// @nodoc /// @nodoc
@ -57,21 +54,21 @@ class _$KeyCustomizationCopyWithImpl<$Res, $Val extends KeyCustomization>
@override @override
$Res call({ $Res call({
Object? serial = null, Object? serial = null,
Object? customName = freezed, Object? name = freezed,
Object? customColor = freezed, Object? color = freezed,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
serial: null == serial serial: null == serial
? _value.serial ? _value.serial
: serial // ignore: cast_nullable_to_non_nullable : serial // ignore: cast_nullable_to_non_nullable
as String, as String,
customName: freezed == customName name: freezed == name
? _value.customName ? _value.name
: customName // ignore: cast_nullable_to_non_nullable : name // ignore: cast_nullable_to_non_nullable
as String?, as String?,
customColor: freezed == customColor color: freezed == color
? _value.customColor ? _value.color
: customColor // ignore: cast_nullable_to_non_nullable : color // ignore: cast_nullable_to_non_nullable
as Color?, as Color?,
) as $Val); ) as $Val);
} }
@ -85,10 +82,7 @@ abstract class _$$KeyCustomizationImplCopyWith<$Res>
__$$KeyCustomizationImplCopyWithImpl<$Res>; __$$KeyCustomizationImplCopyWithImpl<$Res>;
@override @override
@useResult @useResult
$Res call( $Res call({String serial, String? name, @_ColorConverter() Color? color});
{String serial,
String? customName,
@_ColorConverter() Color? customColor});
} }
/// @nodoc /// @nodoc
@ -103,21 +97,21 @@ class __$$KeyCustomizationImplCopyWithImpl<$Res>
@override @override
$Res call({ $Res call({
Object? serial = null, Object? serial = null,
Object? customName = freezed, Object? name = freezed,
Object? customColor = freezed, Object? color = freezed,
}) { }) {
return _then(_$KeyCustomizationImpl( return _then(_$KeyCustomizationImpl(
serial: null == serial serial: null == serial
? _value.serial ? _value.serial
: serial // ignore: cast_nullable_to_non_nullable : serial // ignore: cast_nullable_to_non_nullable
as String, as String,
customName: freezed == customName name: freezed == name
? _value.customName ? _value.name
: customName // ignore: cast_nullable_to_non_nullable : name // ignore: cast_nullable_to_non_nullable
as String?, as String?,
customColor: freezed == customColor color: freezed == color
? _value.customColor ? _value.color
: customColor // ignore: cast_nullable_to_non_nullable : color // ignore: cast_nullable_to_non_nullable
as Color?, as Color?,
)); ));
} }
@ -127,9 +121,7 @@ class __$$KeyCustomizationImplCopyWithImpl<$Res>
@JsonSerializable() @JsonSerializable()
class _$KeyCustomizationImpl implements _KeyCustomization { class _$KeyCustomizationImpl implements _KeyCustomization {
_$KeyCustomizationImpl( _$KeyCustomizationImpl(
{required this.serial, {required this.serial, this.name, @_ColorConverter() this.color});
this.customName,
@_ColorConverter() this.customColor});
factory _$KeyCustomizationImpl.fromJson(Map<String, dynamic> json) => factory _$KeyCustomizationImpl.fromJson(Map<String, dynamic> json) =>
_$$KeyCustomizationImplFromJson(json); _$$KeyCustomizationImplFromJson(json);
@ -137,14 +129,14 @@ class _$KeyCustomizationImpl implements _KeyCustomization {
@override @override
final String serial; final String serial;
@override @override
final String? customName; final String? name;
@override @override
@_ColorConverter() @_ColorConverter()
final Color? customColor; final Color? color;
@override @override
String toString() { String toString() {
return 'KeyCustomization(serial: $serial, customName: $customName, customColor: $customColor)'; return 'KeyCustomization(serial: $serial, name: $name, color: $color)';
} }
@override @override
@ -153,15 +145,13 @@ class _$KeyCustomizationImpl implements _KeyCustomization {
(other.runtimeType == runtimeType && (other.runtimeType == runtimeType &&
other is _$KeyCustomizationImpl && other is _$KeyCustomizationImpl &&
(identical(other.serial, serial) || other.serial == serial) && (identical(other.serial, serial) || other.serial == serial) &&
(identical(other.customName, customName) || (identical(other.name, name) || other.name == name) &&
other.customName == customName) && (identical(other.color, color) || other.color == color));
(identical(other.customColor, customColor) ||
other.customColor == customColor));
} }
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
int get hashCode => Object.hash(runtimeType, serial, customName, customColor); int get hashCode => Object.hash(runtimeType, serial, name, color);
@JsonKey(ignore: true) @JsonKey(ignore: true)
@override @override
@ -181,8 +171,8 @@ class _$KeyCustomizationImpl implements _KeyCustomization {
abstract class _KeyCustomization implements KeyCustomization { abstract class _KeyCustomization implements KeyCustomization {
factory _KeyCustomization( factory _KeyCustomization(
{required final String serial, {required final String serial,
final String? customName, final String? name,
@_ColorConverter() final Color? customColor}) = _$KeyCustomizationImpl; @_ColorConverter() final Color? color}) = _$KeyCustomizationImpl;
factory _KeyCustomization.fromJson(Map<String, dynamic> json) = factory _KeyCustomization.fromJson(Map<String, dynamic> json) =
_$KeyCustomizationImpl.fromJson; _$KeyCustomizationImpl.fromJson;
@ -190,10 +180,10 @@ abstract class _KeyCustomization implements KeyCustomization {
@override @override
String get serial; String get serial;
@override @override
String? get customName; String? get name;
@override @override
@_ColorConverter() @_ColorConverter()
Color? get customColor; Color? get color;
@override @override
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$$KeyCustomizationImplCopyWith<_$KeyCustomizationImpl> get copyWith => _$$KeyCustomizationImplCopyWith<_$KeyCustomizationImpl> get copyWith =>

View File

@ -10,15 +10,14 @@ _$KeyCustomizationImpl _$$KeyCustomizationImplFromJson(
Map<String, dynamic> json) => Map<String, dynamic> json) =>
_$KeyCustomizationImpl( _$KeyCustomizationImpl(
serial: json['serial'] as String, serial: json['serial'] as String,
customName: json['custom_name'] as String?, name: json['name'] as String?,
customColor: color: const _ColorConverter().fromJson(json['color'] as int?),
const _ColorConverter().fromJson(json['custom_color'] as int?),
); );
Map<String, dynamic> _$$KeyCustomizationImplToJson( Map<String, dynamic> _$$KeyCustomizationImplToJson(
_$KeyCustomizationImpl instance) => _$KeyCustomizationImpl instance) =>
<String, dynamic>{ <String, dynamic>{
'serial': instance.serial, 'serial': instance.serial,
'custom_name': instance.customName, 'name': instance.name,
'custom_color': const _ColorConverter().toJson(instance.customColor), 'color': const _ColorConverter().toJson(instance.color),
}; };

View File

@ -52,8 +52,8 @@ class _KeyCustomizationDialogState
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_customName = widget.initialCustomization?.customName; _customName = widget.initialCustomization?.name;
_customColor = widget.initialCustomization?.customColor; _customColor = widget.initialCustomization?.color;
} }
@override @override
@ -100,8 +100,8 @@ class _KeyCustomizationDialogState
final manager = ref.read(keyCustomizationManagerProvider); final manager = ref.read(keyCustomizationManagerProvider);
manager.set( manager.set(
serial: widget.initialCustomization!.serial, serial: widget.initialCustomization!.serial,
customName: _customName, name: _customName,
customColor: _customColor); color: _customColor);
await manager.write(); await manager.write();
ref.invalidate(lightThemeProvider); ref.invalidate(lightThemeProvider);

View File

@ -195,7 +195,7 @@ class ThemeNotifier extends Notifier<ThemeData> {
if (yubiKeyData != null) { if (yubiKeyData != null) {
final manager = ref.read(keyCustomizationManagerProvider); final manager = ref.read(keyCustomizationManagerProvider);
final customization = manager.get(yubiKeyData.info.serial?.toString()); final customization = manager.get(yubiKeyData.info.serial?.toString());
primaryColor = customization?.customColor ?? color; primaryColor = customization?.color ?? color;
if (primaryColor != null) { if (primaryColor != null) {
// remember the last used color // remember the last used color
prefs.setString( prefs.setString(

View File

@ -417,7 +417,7 @@ _DeviceRow _buildDeviceRow(
final keyCustomization = final keyCustomization =
ref.read(keyCustomizationManagerProvider).get(info?.serial?.toString()); ref.read(keyCustomizationManagerProvider).get(info?.serial?.toString());
String displayName = keyCustomization?.customName ?? node.name; String displayName = keyCustomization?.name ?? node.name;
return _DeviceRow( return _DeviceRow(
key: ValueKey(node.path.key), key: ValueKey(node.path.key),
@ -453,8 +453,8 @@ _DeviceRow _buildCurrentDeviceRow(
final keyCustomization = final keyCustomization =
ref.read(keyCustomizationManagerProvider).get(serialNumber); ref.read(keyCustomizationManagerProvider).get(serialNumber);
String displayName = keyCustomization?.customName ?? title; String displayName = keyCustomization?.name ?? title;
Color? displayColor = keyCustomization?.customColor; Color? displayColor = keyCustomization?.color;
return _DeviceRow( return _DeviceRow(
key: keys.deviceInfoListTile, key: keys.deviceInfoListTile,