✨ 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:flutter/services.dart'; | ||||||
| import 'package:gap/gap.dart'; | import 'package:gap/gap.dart'; | ||||||
| import 'package:hooks_riverpod/hooks_riverpod.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/alert.dart'; | ||||||
| import 'package:island/widgets/app_scaffold.dart'; | import 'package:island/widgets/app_scaffold.dart'; | ||||||
| import 'package:material_symbols_icons/symbols.dart'; | import 'package:material_symbols_icons/symbols.dart'; | ||||||
| @@ -68,7 +68,7 @@ class _AboutScreenState extends ConsumerState<AboutScreen> { | |||||||
|     try { |     try { | ||||||
|       final deviceInfoPlugin = DeviceInfoPlugin(); |       final deviceInfoPlugin = DeviceInfoPlugin(); | ||||||
|       _deviceInfo = await deviceInfoPlugin.deviceInfo; |       _deviceInfo = await deviceInfoPlugin.deviceInfo; | ||||||
|       _deviceUdid = await getUdid(); |       _deviceUdid = await udid.getUdid(); | ||||||
|       if (mounted) { |       if (mounted) { | ||||||
|         setState(() {}); |         setState(() {}); | ||||||
|       } |       } | ||||||
| @@ -174,12 +174,20 @@ class _AboutScreenState extends ConsumerState<AboutScreen> { | |||||||
|                             context, |                             context, | ||||||
|                             title: 'Device Information', |                             title: 'Device Information', | ||||||
|                             children: [ |                             children: [ | ||||||
|                               _buildInfoItem( |                               FutureBuilder<String>( | ||||||
|  |                                 future: udid.getDeviceName(), | ||||||
|  |                                 builder: (context, snapshot) { | ||||||
|  |                                   final value = | ||||||
|  |                                       snapshot.hasData | ||||||
|  |                                           ? snapshot.data! | ||||||
|  |                                           : 'unknown'.tr(); | ||||||
|  |                                   return _buildInfoItem( | ||||||
|                                     context, |                                     context, | ||||||
|                                     icon: Symbols.label, |                                     icon: Symbols.label, | ||||||
|                                     label: 'aboutDeviceName'.tr(), |                                     label: 'aboutDeviceName'.tr(), | ||||||
|                                 value: |                                     value: value, | ||||||
|                                     _deviceInfo?.data['name'] ?? 'unknown'.tr(), |                                   ); | ||||||
|  |                                 }, | ||||||
|                               ), |                               ), | ||||||
|                               _buildInfoItem( |                               _buildInfoItem( | ||||||
|                                 context, |                                 context, | ||||||
|   | |||||||
| @@ -1,9 +1,6 @@ | |||||||
| import 'dart:convert'; | import 'dart:convert'; | ||||||
| import 'dart:io'; |  | ||||||
| import 'dart:math' as math; | import 'dart:math' as math; | ||||||
|  |  | ||||||
| import 'package:animations/animations.dart'; | import 'package:animations/animations.dart'; | ||||||
| import 'package:device_info_plus/device_info_plus.dart'; |  | ||||||
| import 'package:dio/dio.dart'; | import 'package:dio/dio.dart'; | ||||||
| import 'package:easy_localization/easy_localization.dart'; | import 'package:easy_localization/easy_localization.dart'; | ||||||
| import 'package:flutter/foundation.dart'; | import 'package:flutter/foundation.dart'; | ||||||
| @@ -42,22 +39,6 @@ final Map<int, (String, String, IconData)> kFactorTypes = { | |||||||
|   4: ('authFactorPin', 'authFactorPinDescription', Symbols.nest_secure_alarm), |   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 { | class LoginScreen extends HookConsumerWidget { | ||||||
|   const LoginScreen({super.key}); |   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'; | import 'package:flutter_udid/flutter_udid.dart'; | ||||||
|  |  | ||||||
| String? _cachedUdid; | String? _cachedUdid; | ||||||
| @@ -9,3 +12,18 @@ Future<String> getUdid() async { | |||||||
|   _cachedUdid = await FlutterUdid.consistentUdid; |   _cachedUdid = await FlutterUdid.consistentUdid; | ||||||
|   return _cachedUdid!; |   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); |   final hash = sha256.convert(bytes); | ||||||
|   return hash.toString(); |   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( |           Column( | ||||||
|             mainAxisAlignment: MainAxisAlignment.spaceBetween, |             mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||||||
|             spacing: 3, |             crossAxisAlignment: CrossAxisAlignment.end, | ||||||
|             children: [ |             children: [ | ||||||
|               AnimatedSwitcher( |               AnimatedSwitcher( | ||||||
|                 duration: const Duration(milliseconds: 300), |                 duration: const Duration(milliseconds: 300), | ||||||
| @@ -244,7 +244,7 @@ class CheckInWidget extends HookConsumerWidget { | |||||||
|                   loading: () => Text('checkInNone').tr().fontSize(15).bold(), |                   loading: () => Text('checkInNone').tr().fontSize(15).bold(), | ||||||
|                   error: (err, stack) => Text('error').tr().fontSize(15).bold(), |                   error: (err, stack) => Text('error').tr().fontSize(15).bold(), | ||||||
|                 ), |                 ), | ||||||
|               ), |               ).padding(right: 4), | ||||||
|               IconButton.outlined( |               IconButton.outlined( | ||||||
|                 iconSize: 16, |                 iconSize: 16, | ||||||
|                 visualDensity: const VisualDensity( |                 visualDensity: const VisualDensity( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user