Skip to content

Commit

Permalink
Copy con mode pin to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Dec 1, 2024
1 parent 47baedf commit b565fa2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Frontend/Widgets/manage_gear.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tail_app/Backend/move_lists.dart';
import 'package:tail_app/Frontend/Widgets/tutorial_card.dart';
Expand Down Expand Up @@ -271,13 +272,14 @@ class ManageGearConventionMode extends ConsumerWidget {
builder: (context, connectivityState, child) => Switch(
value: device.baseStoredDevice.conModeEnabled,
onChanged: connectivityState == ConnectivityState.connected
? (value) {
? (value) async {
//reject if gear disconnected
if (value) {
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "SETPUSSKEY ${device.baseStoredDevice.conModePin}", device: device, timestamp: DateTime.timestamp());
device.commandQueue.addCommand(bluetoothMessage);
device.baseStoredDevice.conModeEnabled = true;
ref.read(knownDevicesProvider.notifier).store();
await Clipboard.setData(ClipboardData(text: device.baseStoredDevice.conModePin));
} else {
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "STOPPUSSKEY", device: device, timestamp: DateTime.timestamp());
device.commandQueue.addCommand(bluetoothMessage);
Expand Down
12 changes: 11 additions & 1 deletion lib/Frontend/Widgets/pincode_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';

import '../translation_string_definitions.dart';
Expand All @@ -12,7 +13,16 @@ class PincodeDialog extends StatelessWidget {
Widget build(BuildContext context) {
return AlertDialog(
actionsAlignment: MainAxisAlignment.center,
actions: [TextButton(onPressed: () => context.pop(), child: Text(ok()))],
actions: [
TextButton(
onPressed: () async => await Clipboard.setData(ClipboardData(text: pin)),
child: Text(manageGearConModePincodeCopy()),
),
TextButton(
onPressed: () => context.pop(),
child: Text(ok()),
),
],
title: Text(manageGearConModePincodeTitle()),
content: Column(
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/translation_string_definitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,6 @@ String manageGearConModeDescription() => Intl.message('Convention Mode is an add

String manageGearConModePincodeTitle() => Intl.message('View Pin Code', name: 'manageGearConModePincodeTitle', desc: 'The description for the pin mode button on the gear page');

String manageGearConModePincodeCopy() => Intl.message('Copy to Clipboard', name: 'manageGearConModePincodeCopy', desc: 'The description for copy to clipboard button on the pin code dialog');

String manageGearConModeToggleTitle() => Intl.message('Enable Convention Mode', name: 'manageGearConModeToggleTitle', desc: 'The description for the convention mode enabled button on the gear page');

0 comments on commit b565fa2

Please sign in to comment.