From 9d008bb0a6ea0ceff3812e9d5cf314ce5514fd1c Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 3 Mar 2023 16:29:24 +0100 Subject: [PATCH] Use TargetPlatform for isDesktop/isAndroid. --- lib/app/app_url_launcher.dart | 8 ++++---- lib/app/views/device_picker_dialog.dart | 7 ++----- lib/app/views/settings_page.dart | 4 ++-- lib/core/state.dart | 15 +++++++++++---- lib/oath/views/add_account_page.dart | 5 ++--- lib/oath/views/key_actions.dart | 5 ++--- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/app/app_url_launcher.dart b/lib/app/app_url_launcher.dart index 6fc23f19..bc4a4163 100644 --- a/lib/app/app_url_launcher.dart +++ b/lib/app/app_url_launcher.dart @@ -14,15 +14,15 @@ * limitations under the License. */ -import 'dart:io'; - import 'package:url_launcher/url_launcher.dart'; -void launchFeedbackUrl() => _launchUrl(Platform.isAndroid +import '../core/state.dart'; + +void launchFeedbackUrl() => _launchUrl(isAndroid ? 'https://yubi.co/ya-feedback-android' : 'https://yubi.co/ya-feedback-desktop'); -void launchHelpUrl() => _launchUrl(Platform.isAndroid +void launchHelpUrl() => _launchUrl(isAndroid ? 'https://yubi.co/ya-help-android' : 'https://yubi.co/ya-help-desktop'); diff --git a/lib/app/views/device_picker_dialog.dart b/lib/app/views/device_picker_dialog.dart index 7abfa14b..d370afd6 100755 --- a/lib/app/views/device_picker_dialog.dart +++ b/lib/app/views/device_picker_dialog.dart @@ -14,8 +14,6 @@ * limitations under the License. */ -import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -115,14 +113,13 @@ class _DevicePickerContent extends ConsumerWidget { _HeroAvatar( child: DeviceAvatar( radius: 64, - child: Icon(Platform.isAndroid ? Icons.no_cell : Icons.usb), + child: Icon(isAndroid ? Icons.no_cell : Icons.usb), ), ), ListTile( title: Center(child: Text(l10n.l_no_yk_present)), subtitle: Center( - child: Text( - Platform.isAndroid ? l10n.l_insert_or_tap_yk : l10n.s_usb)), + child: Text(isAndroid ? l10n.l_insert_or_tap_yk : l10n.s_usb)), ), ], ); diff --git a/lib/app/views/settings_page.dart b/lib/app/views/settings_page.dart index 0989d17e..a2d16d45 100755 --- a/lib/app/views/settings_page.dart +++ b/lib/app/views/settings_page.dart @@ -16,12 +16,12 @@ import 'dart:ui'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../android/views/settings_views.dart'; +import '../../core/state.dart'; import '../../widgets/list_title.dart'; import '../../widgets/responsive_dialog.dart'; import '../state.dart'; @@ -127,7 +127,7 @@ class SettingsPage extends ConsumerWidget { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (defaultTargetPlatform == TargetPlatform.android) ...[ + if (isAndroid) ...[ ListTitle(l10n.s_nfc_options), const NfcTapActionView(), const NfcKbdLayoutView(), diff --git a/lib/core/state.dart b/lib/core/state.dart index bb336591..6dd6f6ec 100644 --- a/lib/core/state.dart +++ b/lib/core/state.dart @@ -14,14 +14,21 @@ * limitations under the License. */ -import 'dart:io'; - import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:shared_preferences/shared_preferences.dart'; -final isDesktop = Platform.isWindows || Platform.isMacOS || Platform.isLinux; -final isAndroid = Platform.isAndroid; +bool get isDesktop { + return const [ + TargetPlatform.windows, + TargetPlatform.macOS, + TargetPlatform.linux + ].contains(defaultTargetPlatform); +} + +bool get isAndroid { + return defaultTargetPlatform == TargetPlatform.android; +} // This must be initialized before use, in main.dart. final prefProvider = Provider((ref) { diff --git a/lib/oath/views/add_account_page.dart b/lib/oath/views/add_account_page.dart index ed63a7b1..839a70ac 100755 --- a/lib/oath/views/add_account_page.dart +++ b/lib/oath/views/add_account_page.dart @@ -16,7 +16,6 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; import 'dart:math'; import 'package:flutter/material.dart'; @@ -177,7 +176,7 @@ class _OathAddAccountPageState extends ConsumerState { final l10n = AppLocalizations.of(context)!; try { if (devicePath == null) { - assert(Platform.isAndroid, 'devicePath is only optional for Android'); + assert(isAndroid, 'devicePath is only optional for Android'); await ref .read(addCredentialToAnyProvider) .call(credUri, requireTouch: _touch); @@ -334,7 +333,7 @@ class _OathAddAccountPageState extends ConsumerState { final devicePath = deviceNode?.path; if (devicePath != null) { await _doAddCredential(devicePath: devicePath, credUri: cred.toUri()); - } else if (Platform.isAndroid) { + } else if (isAndroid) { // Send the credential to Android to be added to the next YubiKey await _doAddCredential(devicePath: null, credUri: cred.toUri()); } else { diff --git a/lib/oath/views/key_actions.dart b/lib/oath/views/key_actions.dart index 635ef26e..56fb5fb7 100755 --- a/lib/oath/views/key_actions.dart +++ b/lib/oath/views/key_actions.dart @@ -14,8 +14,6 @@ * limitations under the License. */ -import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -24,6 +22,7 @@ import 'package:yubico_authenticator/oath/icon_provider/icon_pack_dialog.dart'; import '../../app/message.dart'; import '../../app/models.dart'; import '../../app/state.dart'; +import '../../core/state.dart'; import '../../exception/cancellation_exception.dart'; import '../../widgets/list_title.dart'; import '../models.dart'; @@ -59,7 +58,7 @@ Widget oathBuildActions( ? () async { Navigator.of(context).pop(); CredentialData? otpauth; - if (Platform.isAndroid) { + if (isAndroid) { final scanner = ref.read(qrScannerProvider); if (scanner != null) { try {