diff --git a/lib/screen/home/home_navigation_page.dart b/lib/screen/home/home_navigation_page.dart index d4ed59360..aab1d5952 100644 --- a/lib/screen/home/home_navigation_page.dart +++ b/lib/screen/home/home_navigation_page.dart @@ -6,6 +6,7 @@ // import 'dart:async'; +import 'dart:io'; import 'package:after_layout/after_layout.dart'; import 'package:autonomy_flutter/common/injector.dart'; @@ -42,6 +43,7 @@ import 'package:autonomy_flutter/util/au_icons.dart'; import 'package:autonomy_flutter/util/constants.dart'; import 'package:autonomy_flutter/util/dio_util.dart'; import 'package:autonomy_flutter/util/inapp_notifications.dart'; +import 'package:autonomy_flutter/util/local_network_helper.dart'; import 'package:autonomy_flutter/util/log.dart'; import 'package:autonomy_flutter/util/style.dart'; import 'package:autonomy_flutter/util/ui_helper.dart'; @@ -318,6 +320,18 @@ class HomeNavigationPageState extends State unawaited(injector().init()); unawaited(_syncArtist()); + + unawaited(_requestLocalNetworkPermission()); + } + + Future _requestLocalNetworkPermission() async { + if (Platform.isIOS) { + final didRequest = _configurationService.didGetLocalNetworkPermission(); + if (!didRequest) { + final result = await LocalNetworkHelper.requestLocalNetworkPermission(); + await _configurationService.setDidGetLocalNetworkPermission(result); + } + } } Future _syncArtist() async { diff --git a/lib/service/canvas_client_service.dart b/lib/service/canvas_client_service.dart index 0b1129c03..f45acc95e 100644 --- a/lib/service/canvas_client_service.dart +++ b/lib/service/canvas_client_service.dart @@ -78,7 +78,6 @@ class CanvasClientService { ..device = (DeviceInfo() ..deviceId = _deviceId ..deviceName = _deviceName); - final response = await stub.connect( request, options: _callOptions, diff --git a/lib/service/configuration_service.dart b/lib/service/configuration_service.dart index 1f3b6bf9b..c6223c669 100644 --- a/lib/service/configuration_service.dart +++ b/lib/service/configuration_service.dart @@ -29,6 +29,10 @@ import 'package:uuid/uuid.dart'; //ignore_for_file: constant_identifier_names abstract class ConfigurationService { + bool didGetLocalNetworkPermission(); + + Future setDidGetLocalNetworkPermission(bool value); + Future setRecordOwners(List owners, {bool override = false}); List getRecordOwners(); @@ -277,6 +281,8 @@ abstract class ConfigurationService { } class ConfigurationServiceImpl implements ConfigurationService { + static const String keyDidGetLocalNetWorkPermission = + 'did_get_local_network_permission'; static const String keyRecordOwners = 'yoko_ono_record_owners'; static const String KEY_HAS_MERCHANDISE_SUPPORT_INDEX_ID = 'has_merchandise_support'; @@ -1221,6 +1227,15 @@ class ConfigurationServiceImpl implements ConfigurationService { await _preferences.setStringList(keyRecordOwners, currentOwners.toList()); } } + + @override + bool didGetLocalNetworkPermission() => + _preferences.getBool(keyDidGetLocalNetWorkPermission) ?? false; + + @override + Future setDidGetLocalNetworkPermission(bool value) async { + await _preferences.setBool(keyDidGetLocalNetWorkPermission, value); + } } enum ConflictAction { diff --git a/lib/util/local_network_helper.dart b/lib/util/local_network_helper.dart new file mode 100644 index 000000000..5e3ae199e --- /dev/null +++ b/lib/util/local_network_helper.dart @@ -0,0 +1,21 @@ +import 'dart:io'; + +import 'package:autonomy_flutter/util/log.dart'; +import 'package:network_info_plus/network_info_plus.dart'; + +class LocalNetworkHelper { + static Future requestLocalNetworkPermission() async { + bool isGranted = false; + try { + final wifiIp = await NetworkInfo().getWifiIP(); + log.info('[LocalNetworkHelper] wifiIp: $wifiIp'); + await Socket.connect(wifiIp, 80, + timeout: const Duration(milliseconds: 100)); + isGranted = true; + } catch (e) { + log.info('[LocalNetworkHelper] requestLocalNetworkPermission Error: $e'); + isGranted = false; + } + return isGranted; + } +} diff --git a/pubspec.lock b/pubspec.lock index 076cd8041..efa0ba335 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1858,6 +1858,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + network_info_plus: + dependency: "direct main" + description: + name: network_info_plus + sha256: "5bd4b86e28fed5ed4e6ac7764133c031dfb7d3f46aa2a81b46f55038aa78ecc0" + url: "https://pub.dev" + source: hosted + version: "5.0.3" + network_info_plus_platform_interface: + dependency: transitive + description: + name: network_info_plus_platform_interface + sha256: "2e193d61d3072ac17824638793d3b89c6d581ce90c11604f4ca87311b42f2706" + url: "https://pub.dev" + source: hosted + version: "2.0.0" nft_collection: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0976764de..fd3edb82e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -159,6 +159,7 @@ dependencies: image_gallery_saver: ^2.0.3 hand_signature: ^3.0.1 flutter_pdfview: ^1.3.2 + network_info_plus: ^5.0.3 dependency_overrides: intl: 0.18.0