fix node QR Code URI parsing (#1916)

* fix:node QR Code URI parsing

* optionally include user data

* fix for qr scaner
This commit is contained in:
Serhii 2025-01-24 20:05:08 +02:00 committed by GitHub
parent c88809133f
commit 4fe2be3c92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 16 deletions

View file

@ -23,7 +23,7 @@ Future<String> presentQRScanner(BuildContext context) async {
), ),
); );
isQrScannerShown = false; isQrScannerShown = false;
return result??''; return result!;
} catch (e) { } catch (e) {
isQrScannerShown = false; isQrScannerShown = false;
rethrow; rethrow;
@ -95,9 +95,7 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
setState(() { setState(() {
popped = true; popped = true;
}); });
SchedulerBinding.instance.addPostFrameCallback((_) { Navigator.of(context).pop(_barcode!.rawValue ?? _barcode!.rawBytes);
Navigator.of(context).pop(_barcode?.rawValue ?? "");
});
} }
} }
} }

View file

@ -58,6 +58,12 @@ class NodeForm extends StatelessWidget {
} }
}); });
reaction((_) => nodeViewModel.path, (String path) {
if (path != _pathController.text) {
_pathController.text = path;
}
});
_addressController.addListener(() => nodeViewModel.address = _addressController.text); _addressController.addListener(() => nodeViewModel.address = _addressController.text);
_pathController.addListener(() => nodeViewModel.path = _pathController.text); _pathController.addListener(() => nodeViewModel.path = _pathController.text);
_portController.addListener(() => nodeViewModel.port = _portController.text); _portController.addListener(() => nodeViewModel.port = _portController.text);

View file

@ -219,23 +219,22 @@ abstract class NodeCreateOrEditViewModelBase with Store {
throw Exception('Unexpected scan QR code value: value is empty'); throw Exception('Unexpected scan QR code value: value is empty');
} }
if (!code.contains('://')) code = 'tcp://$code';
final uri = Uri.tryParse(code); final uri = Uri.tryParse(code);
if (uri == null || uri.host.isEmpty) {
if (uri == null) { throw Exception('Invalid QR code: Unable to parse or missing host.');
throw Exception('Unexpected scan QR code value: Value is invalid');
} }
final userInfo = uri.userInfo.split(':'); final userInfo = uri.userInfo;
if (userInfo.length < 2) {
throw Exception('Unexpected scan QR code value: Value is invalid');
}
final rpcUser = userInfo[0];
final rpcPassword = userInfo[1];
final ipAddress = uri.host; final ipAddress = uri.host;
final port = uri.port.toString(); final port = uri.hasPort ? uri.port.toString() : '';
final path = uri.path; final path = uri.path;
final queryParams = uri.queryParameters; // Currently not used
final rpcUser = userInfo.split(':').first;
final rpcPassword = userInfo.split(':').length > 1 ? userInfo.split(':')[1] : '';
await Future.delayed(Duration(milliseconds: 345));
setAddress(ipAddress); setAddress(ipAddress);
setPath(path); setPath(path);