| 1 | import 'dart:io'; |
| 2 | import 'package:cake_wallet/utils/package_info.dart'; |
| 3 | import 'package:cw_core/utils/print_verbose.dart'; |
| 4 | |
| 5 | enum DistributionType { googleplay, github, appstore, fdroid } |
| 6 | |
| 7 | class DistributionInfo { |
| 8 | DistributionInfo._(); |
| 9 | |
| 10 | static DistributionInfo get instance => DistributionInfo._(); |
| 11 | |
| 12 | Future<String> getDistributionPath() async { |
| 13 | final isPlayStore = await isInstalledFromPlayStore(); |
| 14 | final distributionPath = _getDistributionPath(isPlayStore); |
| 15 | |
| 16 | return distributionPath.name; |
| 17 | } |
| 18 | |
| 19 | DistributionType _getDistributionPath(bool isPlayStore) { |
| 20 | if (isPlayStore) { |
| 21 | return DistributionType.googleplay; |
| 22 | } else if (Platform.isAndroid) { |
| 23 | return DistributionType.github; |
| 24 | } else if (Platform.isIOS) { |
| 25 | return DistributionType.appstore; |
| 26 | } else { |
| 27 | return DistributionType.github; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | Future<bool> isInstalledFromPlayStore() async { |
| 32 | try { |
| 33 | final packageInfo = await PackageInfo.fromPlatform(); |
| 34 | return packageInfo.packageName == 'com.android.vending'; |
| 35 | } catch (e) { |
| 36 | printV('Error: $e'); |
| 37 | return false; |
| 38 | } |
| 39 | } |
| 40 | } |