Skip to content

Commit

Permalink
feat: duplicate global keyconfiguration to support save function
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeLayer committed Oct 21, 2024
1 parent 5bac0a8 commit 4de5d2c
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 117 deletions.
9 changes: 6 additions & 3 deletions configurator/lib/components/device_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ class _DeviceSelectorState extends State<DeviceSelector> {
setState(() {
_selectedDeviceState =
result ? SelectedDeviceState.valid : SelectedDeviceState.invalid;
if (!result) {
});
if (!result) {
setState(() {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(EventNotifier.eventNotifyingMessage(
context, NotifyingEvents.serialDeviceDoesNotResponse))));
}
});
});
return;
}
},
);
}
Expand Down
168 changes: 84 additions & 84 deletions configurator/lib/components/key_config_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,73 +30,73 @@ class _KeyConfigListState extends State<KeyConfigList> {
return <KeyConfigListItemContainer>[
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneLeftSide,
key: Globals.instance.keyConfig.tuneLeftSide.keycode,
enabled: Globals.instance.keyConfig.tuneLeftSide.enabled,
key: Globals.instance.updatedKeyConfig.tuneLeftSide.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneLeftSide.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneLeftSide.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneLeftSide.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneS,
key: Globals.instance.keyConfig.tuneS.keycode,
enabled: Globals.instance.keyConfig.tuneS.enabled,
key: Globals.instance.updatedKeyConfig.tuneS.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneS.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneS.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneS.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneD,
key: Globals.instance.keyConfig.tuneD.keycode,
enabled: Globals.instance.keyConfig.tuneD.enabled,
key: Globals.instance.updatedKeyConfig.tuneD.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneD.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneD.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneD.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneF,
key: Globals.instance.keyConfig.tuneF.keycode,
enabled: Globals.instance.keyConfig.tuneF.enabled,
key: Globals.instance.updatedKeyConfig.tuneF.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneF.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneF.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneF.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneF,
key: Globals.instance.keyConfig.tuneC.keycode,
enabled: Globals.instance.keyConfig.tuneC.enabled,
key: Globals.instance.updatedKeyConfig.tuneC.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneC.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneC.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneC.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneF,
key: Globals.instance.keyConfig.tuneM.keycode,
enabled: Globals.instance.keyConfig.tuneM.enabled,
key: Globals.instance.updatedKeyConfig.tuneM.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneM.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneM.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneM.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneJ,
key: Globals.instance.keyConfig.tuneJ.keycode,
enabled: Globals.instance.keyConfig.tuneJ.enabled,
key: Globals.instance.updatedKeyConfig.tuneJ.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneJ.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneJ.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneJ.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneK,
key: Globals.instance.keyConfig.tuneK.keycode,
enabled: Globals.instance.keyConfig.tuneK.enabled,
key: Globals.instance.updatedKeyConfig.tuneK.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneK.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneK.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneK.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneL,
key: Globals.instance.keyConfig.tuneL.keycode,
enabled: Globals.instance.keyConfig.tuneL.enabled,
key: Globals.instance.updatedKeyConfig.tuneL.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneL.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneL.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneL.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTuneRightSide,
key: Globals.instance.keyConfig.tuneRightSide.keycode,
enabled: Globals.instance.keyConfig.tuneRightSide.enabled,
key: Globals.instance.updatedKeyConfig.tuneRightSide.keycode,
enabled: Globals.instance.updatedKeyConfig.tuneRightSide.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tuneRightSide.keycode = keycode;
Globals.instance.updatedKeyConfig.tuneRightSide.keycode = keycode;
}),
];
}
Expand All @@ -106,94 +106,94 @@ class _KeyConfigListState extends State<KeyConfigList> {
return <KeyConfigListItemContainer>[
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEsc,
key: Globals.instance.keyConfig.esc.keycode,
enabled: Globals.instance.keyConfig.esc.enabled,
key: Globals.instance.updatedKeyConfig.esc.keycode,
enabled: Globals.instance.updatedKeyConfig.esc.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.esc.keycode = keycode;
Globals.instance.updatedKeyConfig.esc.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEnter,
key: Globals.instance.keyConfig.enter.keycode,
enabled: Globals.instance.keyConfig.enter.enabled,
key: Globals.instance.updatedKeyConfig.enter.keycode,
enabled: Globals.instance.updatedKeyConfig.enter.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.enter.keycode = keycode;
Globals.instance.updatedKeyConfig.enter.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameTab,
key: Globals.instance.keyConfig.tab.keycode,
enabled: Globals.instance.keyConfig.tab.enabled,
key: Globals.instance.updatedKeyConfig.tab.keycode,
enabled: Globals.instance.updatedKeyConfig.tab.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.tab.keycode = keycode;
Globals.instance.updatedKeyConfig.tab.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameSpace,
key: Globals.instance.keyConfig.space.keycode,
enabled: Globals.instance.keyConfig.space.enabled,
key: Globals.instance.updatedKeyConfig.space.keycode,
enabled: Globals.instance.updatedKeyConfig.space.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.space.keycode = keycode;
Globals.instance.updatedKeyConfig.space.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameSpeedUp,
key: Globals.instance.keyConfig.speedUp.keycode,
enabled: Globals.instance.keyConfig.speedUp.enabled,
key: Globals.instance.updatedKeyConfig.speedUp.keycode,
enabled: Globals.instance.updatedKeyConfig.speedUp.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.speedUp.keycode = keycode;
Globals.instance.updatedKeyConfig.speedUp.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameSpeedDown,
key: Globals.instance.keyConfig.speedDown.keycode,
enabled: Globals.instance.keyConfig.speedDown.enabled,
key: Globals.instance.updatedKeyConfig.speedDown.keycode,
enabled: Globals.instance.updatedKeyConfig.speedDown.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.speedDown.keycode = keycode;
Globals.instance.updatedKeyConfig.speedDown.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameRewind,
key: Globals.instance.keyConfig.rewind.keycode,
enabled: Globals.instance.keyConfig.rewind.enabled,
key: Globals.instance.updatedKeyConfig.rewind.keycode,
enabled: Globals.instance.updatedKeyConfig.rewind.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.rewind.keycode = keycode;
Globals.instance.updatedKeyConfig.rewind.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameLeftShift,
key: Globals.instance.keyConfig.leftShift.keycode,
enabled: Globals.instance.keyConfig.leftShift.enabled,
key: Globals.instance.updatedKeyConfig.leftShift.keycode,
enabled: Globals.instance.updatedKeyConfig.leftShift.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.leftShift.keycode = keycode;
Globals.instance.updatedKeyConfig.leftShift.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameRightShift,
key: Globals.instance.keyConfig.rightShift.keycode,
enabled: Globals.instance.keyConfig.rightShift.enabled,
key: Globals.instance.updatedKeyConfig.rightShift.keycode,
enabled: Globals.instance.updatedKeyConfig.rightShift.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.rightShift.keycode = keycode;
Globals.instance.updatedKeyConfig.rightShift.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameArrowUp,
key: Globals.instance.keyConfig.arrowUp.keycode,
enabled: Globals.instance.keyConfig.arrowUp.enabled,
key: Globals.instance.updatedKeyConfig.arrowUp.keycode,
enabled: Globals.instance.updatedKeyConfig.arrowUp.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.arrowUp.keycode = keycode;
Globals.instance.updatedKeyConfig.arrowUp.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameArrowDown,
key: Globals.instance.keyConfig.arrowDown.keycode,
enabled: Globals.instance.keyConfig.arrowDown.enabled,
key: Globals.instance.updatedKeyConfig.arrowDown.keycode,
enabled: Globals.instance.updatedKeyConfig.arrowDown.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.arrowDown.keycode = keycode;
Globals.instance.updatedKeyConfig.arrowDown.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameArrowLeft,
key: Globals.instance.keyConfig.arrowLeft.keycode,
enabled: Globals.instance.keyConfig.arrowLeft.enabled,
key: Globals.instance.updatedKeyConfig.arrowLeft.keycode,
enabled: Globals.instance.updatedKeyConfig.arrowLeft.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.arrowLeft.keycode = keycode;
Globals.instance.updatedKeyConfig.arrowLeft.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameArrowRight,
key: Globals.instance.keyConfig.arrowRight.keycode,
enabled: Globals.instance.keyConfig.arrowRight.enabled,
key: Globals.instance.updatedKeyConfig.arrowRight.keycode,
enabled: Globals.instance.updatedKeyConfig.arrowRight.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.arrowRight.keycode = keycode;
Globals.instance.updatedKeyConfig.arrowRight.keycode = keycode;
}),
];
}
Expand All @@ -203,38 +203,38 @@ class _KeyConfigListState extends State<KeyConfigList> {
return <KeyConfigListItemContainer>[
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEmoticon1,
key: Globals.instance.keyConfig.emoticon1.keycode,
enabled: Globals.instance.keyConfig.emoticon1.enabled,
key: Globals.instance.updatedKeyConfig.emoticon1.keycode,
enabled: Globals.instance.updatedKeyConfig.emoticon1.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.emoticon1.keycode = keycode;
Globals.instance.updatedKeyConfig.emoticon1.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEmoticon2,
key: Globals.instance.keyConfig.emoticon2.keycode,
enabled: Globals.instance.keyConfig.emoticon2.enabled,
key: Globals.instance.updatedKeyConfig.emoticon2.keycode,
enabled: Globals.instance.updatedKeyConfig.emoticon2.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.emoticon2.keycode = keycode;
Globals.instance.updatedKeyConfig.emoticon2.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEmoticon3,
key: Globals.instance.keyConfig.emoticon3.keycode,
enabled: Globals.instance.keyConfig.emoticon3.enabled,
key: Globals.instance.updatedKeyConfig.emoticon3.keycode,
enabled: Globals.instance.updatedKeyConfig.emoticon3.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.emoticon3.keycode = keycode;
Globals.instance.updatedKeyConfig.emoticon3.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEmoticon4,
key: Globals.instance.keyConfig.emoticon4.keycode,
enabled: Globals.instance.keyConfig.emoticon4.enabled,
key: Globals.instance.updatedKeyConfig.emoticon4.keycode,
enabled: Globals.instance.updatedKeyConfig.emoticon4.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.emoticon4.keycode = keycode;
Globals.instance.updatedKeyConfig.emoticon4.keycode = keycode;
}),
KeyConfigListItemContainer(
name: AppLocalizations.of(context)!.keyNameEmoticon5,
key: Globals.instance.keyConfig.emoticon5.keycode,
enabled: Globals.instance.keyConfig.emoticon5.enabled,
key: Globals.instance.updatedKeyConfig.emoticon5.keycode,
enabled: Globals.instance.updatedKeyConfig.emoticon5.enabled,
handler: (Keycode keycode) {
Globals.instance.keyConfig.emoticon5.keycode = keycode;
Globals.instance.updatedKeyConfig.emoticon5.keycode = keycode;
}),
];
}
Expand Down
2 changes: 2 additions & 0 deletions configurator/lib/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Globals {
String currentLocale = 'kr';

late KeyConfig keyConfig;
late KeyConfig updatedKeyConfig;
late String currentSerialDevicePort;
late Map<String, SerialDevice> _serialDevices;

Expand Down Expand Up @@ -49,6 +50,7 @@ class Globals {
EachKeyConfig(keycode: Keycode.undefined, enabled: false));
// Load from Arduino
keyConfig = BuildConfig.defaultKeyConfig;
updatedKeyConfig = KeyConfig.clone(keyConfig);
_serialDevices = Map<String, SerialDevice>();
return;
keyConfig = KeyConfig(
Expand Down
Loading

0 comments on commit 4de5d2c

Please sign in to comment.