import 'package:get/get.dart'; import 'package:url_launcher/url_launcher.dart'; import '../app/components/ix_snackbar.dart'; import '../app/constants/configs.dart'; import '../app/data/sp/ix_sp.dart'; import '../app/routes/app_pages.dart'; import 'package:flutter_custom_tabs/flutter_custom_tabs.dart' as ct; import '../config/translations/strings_enum.dart'; class SystemHelper { // static Future openEmail(String email) async { // final Uri emailUri = Uri( // scheme: 'mailto', // path: email, // ); // try { // await launchUrl( // emailUri, // mode: LaunchMode.externalApplication, // ); // } catch (e) { // CustomSnackBar.showCustomErrorSnackBar( // title: Strings.error.tr, message: Strings.eUtilOpenEmail.tr); // } // } static Future openGooglePlay(String packageName) async { final String url = 'https://play.google.com/store/apps/details?id=$packageName'; try { // 直接尝试打开 Google Play 应用 await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication); } catch (e) { IXSnackBar.showIXErrorSnackBar( title: Strings.error.tr, message: Strings.eUtilOpenGooglePlay.tr, ); } } static Future openGooglePlayUrl(String url) async { try { // 直接尝试打开 Google Play 应用 await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication); } catch (e) { IXSnackBar.showIXErrorSnackBar( title: Strings.error.tr, message: Strings.eUtilOpenGooglePlay.tr, ); } } static Future openGoogleChrome(String url) async { try { await ct.launchUrl( Uri.parse(url), customTabsOptions: ct.CustomTabsOptions.partial( configuration: ct.PartialCustomTabsConfiguration.adaptiveSheet( initialHeight: Get.height * 0.7, initialWidth: Get.width * 0.4, activitySideSheetMaximizationEnabled: true, activitySideSheetDecorationType: ct.CustomTabsActivitySideSheetDecorationType.shadow, activitySideSheetRoundedCornersPosition: ct.CustomTabsActivitySideSheetRoundedCornersPosition.top, cornerRadius: 16, ), ), safariVCOptions: const ct.SafariViewControllerOptions.pageSheet( configuration: ct.SheetPresentationControllerConfiguration( detents: { ct.SheetPresentationControllerDetent.large, ct.SheetPresentationControllerDetent.medium, }, prefersScrollingExpandsWhenScrolledToEdge: true, prefersGrabberVisible: true, prefersEdgeAttachedInCompactHeight: true, ), dismissButtonStyle: ct.SafariViewControllerDismissButtonStyle.close, ), ); } catch (e) { try { await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication); } catch (e) { IXSnackBar.showIXErrorSnackBar( title: Strings.error.tr, message: Strings.eUtilOpenBrowser.tr, ); } } } static Future closeGoogleChrome() async { await ct.closeCustomTabs(); } static Future openWebPage(String url) async { try { final Uri webUri = Uri.parse(url); await launchUrl(webUri, mode: LaunchMode.externalApplication); } catch (e) { IXSnackBar.showIXErrorSnackBar( title: Strings.error.tr, message: Strings.eUtilOpenBrowser.tr, ); } } static Future openInAppWebPage(String url, String title) async { Get.toNamed(Routes.WEB, arguments: {'url': url, 'title': title}); } static Future handleDeepLink(String deepLink) async { try { final Uri uri = Uri.parse(deepLink); if (await canLaunchUrl(uri)) { await launchUrl(uri, mode: LaunchMode.externalApplication); } else { IXSnackBar.showIXErrorSnackBar( title: Strings.error.tr, message: Strings.unknownError.tr, ); } } catch (e) { IXSnackBar.showIXErrorSnackBar( title: Strings.error.tr, message: Strings.unknownError.tr, ); } } static void openPrivacyTerms() { final launch = IXSP.getLaunch(); if (launch?.appConfig?.privacyAgreement != null && launch?.appConfig?.privacyAgreement?.privacyTermsUrl != null) { String url = launch?.appConfig?.privacyAgreement?.privacyTermsUrl ?? ''; if (url.indexOf("http") != 0) { url = '${Configs.websiteUrl}/$url'; } Get.toNamed( Routes.WEB, arguments: {'url': url, 'title': Strings.privacyPolicy.tr}, ); } else { Get.toNamed( Routes.MARKDOWN, arguments: {'title': Strings.privacyPolicy.tr, 'filename': 'privacy'}, ); } } static void openTermsOfService() { final launch = IXSP.getLaunch(); if (launch?.appConfig?.privacyAgreement != null && launch?.appConfig?.privacyAgreement?.termsOfServiceUrl != null) { String url = launch?.appConfig?.privacyAgreement?.termsOfServiceUrl ?? ''; if (url.indexOf("http") != 0) { url = '${Configs.websiteUrl}/$url'; } Get.toNamed( Routes.WEB, arguments: {'url': url, 'title': Strings.termsOfService.tr}, ); } else { Get.toNamed( Routes.MARKDOWN, arguments: {'title': Strings.termsOfService.tr, 'filename': 'terms'}, ); } } // 打开 JS Bridge 测试页面 static void openTestPage() { Get.toNamed( Routes.WEB, arguments: { // 使用 assets/ 前缀,WebView 会自动使用 loadData 加载 'url': 'assets/html/test_jsbridge.html', 'title': 'JS Bridge 测试', 'fullScreen': true, }, ); } }