✨ Desktop device name, close #7
This commit is contained in:
		| @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:gap/gap.dart'; | ||||
| import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||||
| import 'package:island/services/udid.native.dart'; | ||||
| import 'package:island/services/udid.dart' as udid; | ||||
| import 'package:island/widgets/alert.dart'; | ||||
| import 'package:island/widgets/app_scaffold.dart'; | ||||
| import 'package:material_symbols_icons/symbols.dart'; | ||||
| @@ -68,7 +68,7 @@ class _AboutScreenState extends ConsumerState<AboutScreen> { | ||||
|     try { | ||||
|       final deviceInfoPlugin = DeviceInfoPlugin(); | ||||
|       _deviceInfo = await deviceInfoPlugin.deviceInfo; | ||||
|       _deviceUdid = await getUdid(); | ||||
|       _deviceUdid = await udid.getUdid(); | ||||
|       if (mounted) { | ||||
|         setState(() {}); | ||||
|       } | ||||
| @@ -174,12 +174,20 @@ class _AboutScreenState extends ConsumerState<AboutScreen> { | ||||
|                             context, | ||||
|                             title: 'Device Information', | ||||
|                             children: [ | ||||
|                               _buildInfoItem( | ||||
|                                 context, | ||||
|                                 icon: Symbols.label, | ||||
|                                 label: 'aboutDeviceName'.tr(), | ||||
|                                 value: | ||||
|                                     _deviceInfo?.data['name'] ?? 'unknown'.tr(), | ||||
|                               FutureBuilder<String>( | ||||
|                                 future: udid.getDeviceName(), | ||||
|                                 builder: (context, snapshot) { | ||||
|                                   final value = | ||||
|                                       snapshot.hasData | ||||
|                                           ? snapshot.data! | ||||
|                                           : 'unknown'.tr(); | ||||
|                                   return _buildInfoItem( | ||||
|                                     context, | ||||
|                                     icon: Symbols.label, | ||||
|                                     label: 'aboutDeviceName'.tr(), | ||||
|                                     value: value, | ||||
|                                   ); | ||||
|                                 }, | ||||
|                               ), | ||||
|                               _buildInfoItem( | ||||
|                                 context, | ||||
|   | ||||
| @@ -1,9 +1,6 @@ | ||||
| import 'dart:convert'; | ||||
| import 'dart:io'; | ||||
| import 'dart:math' as math; | ||||
|  | ||||
| import 'package:animations/animations.dart'; | ||||
| import 'package:device_info_plus/device_info_plus.dart'; | ||||
| import 'package:dio/dio.dart'; | ||||
| import 'package:easy_localization/easy_localization.dart'; | ||||
| import 'package:flutter/foundation.dart'; | ||||
| @@ -42,22 +39,6 @@ final Map<int, (String, String, IconData)> kFactorTypes = { | ||||
|   4: ('authFactorPin', 'authFactorPinDescription', Symbols.nest_secure_alarm), | ||||
| }; | ||||
|  | ||||
| Future<String?> getDeviceName() async { | ||||
|   if (kIsWeb) return null; | ||||
|   String? name; | ||||
|   if (Platform.isIOS) { | ||||
|     final deviceInfo = await DeviceInfoPlugin().iosInfo; | ||||
|     name = deviceInfo.name; | ||||
|   } else if (Platform.isAndroid) { | ||||
|     final deviceInfo = await DeviceInfoPlugin().androidInfo; | ||||
|     name = deviceInfo.name; | ||||
|   } else if (Platform.isWindows) { | ||||
|     final deviceInfo = await DeviceInfoPlugin().windowsInfo; | ||||
|     name = deviceInfo.computerName; | ||||
|   } | ||||
|   return name; | ||||
| } | ||||
|  | ||||
| class LoginScreen extends HookConsumerWidget { | ||||
|   const LoginScreen({super.key}); | ||||
|  | ||||
|   | ||||
| @@ -1 +1,3 @@ | ||||
| export 'udid.native.dart' if (dart.library.html) 'udid.web.dart'; | ||||
| export 'udid.native.dart' | ||||
|     if (dart.library.html) 'udid.web.dart' | ||||
|     if (dart.library.io) 'udid.native.dart'; | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| import 'dart:io'; | ||||
| import 'package:device_info_plus/device_info_plus.dart'; | ||||
| import 'package:easy_localization/easy_localization.dart'; | ||||
| import 'package:flutter_udid/flutter_udid.dart'; | ||||
|  | ||||
| String? _cachedUdid; | ||||
| @@ -9,3 +12,18 @@ Future<String> getUdid() async { | ||||
|   _cachedUdid = await FlutterUdid.consistentUdid; | ||||
|   return _cachedUdid!; | ||||
| } | ||||
|  | ||||
| Future<String> getDeviceName() async { | ||||
|   DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); | ||||
|   if (Platform.isAndroid) { | ||||
|     AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; | ||||
|     return androidInfo.device; | ||||
|   } else if (Platform.isIOS) { | ||||
|     IosDeviceInfo iosInfo = await deviceInfo.iosInfo; | ||||
|     return iosInfo.name; | ||||
|   } else if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) { | ||||
|     return Platform.localHostname; | ||||
|   } else { | ||||
|     return 'unknown'.tr(); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -9,3 +9,18 @@ Future<String> getUdid() async { | ||||
|   final hash = sha256.convert(bytes); | ||||
|   return hash.toString(); | ||||
| } | ||||
|  | ||||
| Future<String> getDeviceName() async { | ||||
|   final userAgent = window.navigator.userAgent; | ||||
|   if (userAgent.contains('Chrome') && !userAgent.contains('Edg')) { | ||||
|     return 'Chrome'; | ||||
|   } else if (userAgent.contains('Firefox')) { | ||||
|     return 'Firefox'; | ||||
|   } else if (userAgent.contains('Safari') && !userAgent.contains('Chrome')) { | ||||
|     return 'Safari'; | ||||
|   } else if (userAgent.contains('Edg')) { | ||||
|     return 'Edge'; | ||||
|   } else { | ||||
|     return 'Browser'; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -228,7 +228,7 @@ class CheckInWidget extends HookConsumerWidget { | ||||
|           ), | ||||
|           Column( | ||||
|             mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||||
|             spacing: 3, | ||||
|             crossAxisAlignment: CrossAxisAlignment.end, | ||||
|             children: [ | ||||
|               AnimatedSwitcher( | ||||
|                 duration: const Duration(milliseconds: 300), | ||||
| @@ -244,7 +244,7 @@ class CheckInWidget extends HookConsumerWidget { | ||||
|                   loading: () => Text('checkInNone').tr().fontSize(15).bold(), | ||||
|                   error: (err, stack) => Text('error').tr().fontSize(15).bold(), | ||||
|                 ), | ||||
|               ), | ||||
|               ).padding(right: 4), | ||||
|               IconButton.outlined( | ||||
|                 iconSize: 16, | ||||
|                 visualDensity: const VisualDensity( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user