|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:flutter/foundation.dart'; |
1 | 4 | import 'package:flutter/material.dart'; |
2 | 5 |
|
3 | 6 | import '../generated/l10n/zulip_localizations.dart'; |
4 | 7 | import 'actions.dart'; |
| 8 | +import 'app.dart'; |
5 | 9 |
|
6 | 10 | Widget _dialogActionText(String text) { |
7 | 11 | return Text( |
@@ -112,3 +116,75 @@ DialogStatus<bool> showSuggestedActionDialog({ |
112 | 116 | ])); |
113 | 117 | return DialogStatus(future); |
114 | 118 | } |
| 119 | + |
| 120 | +bool debugDisableBetaCompleteDialog = false; |
| 121 | +void resetDebugDisableBetaCompleteDialog() { |
| 122 | + debugDisableBetaCompleteDialog = false; |
| 123 | +} |
| 124 | + |
| 125 | +/// Show a brief dialog box saying that this beta channel has ended, |
| 126 | +/// offering a way to get the app from prod. |
| 127 | +void showBetaCompleteDialog() async { |
| 128 | + if (debugDisableBetaCompleteDialog) return; |
| 129 | + |
| 130 | + final navigator = await ZulipApp.navigator; |
| 131 | + final context = navigator.context; |
| 132 | + assert(context.mounted); |
| 133 | + if (!context.mounted) return; // TODO(linter): this is impossible as there's no actual async gap, but the use_build_context_synchronously lint doesn't see that |
| 134 | + |
| 135 | + switch (defaultTargetPlatform) { |
| 136 | + case TargetPlatform.android: |
| 137 | + case TargetPlatform.iOS: |
| 138 | + break; |
| 139 | + case TargetPlatform.macOS: |
| 140 | + case TargetPlatform.fuchsia: |
| 141 | + case TargetPlatform.linux: |
| 142 | + case TargetPlatform.windows: |
| 143 | + // Do nothing on these unsupported platforms. |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + final zulipLocalizations = ZulipLocalizations.of(context); |
| 148 | + |
| 149 | + final message = 'Since Zulip’s new Flutter app has launched, this beta app is no longer maintained. We strongly recommend uninstalling it and switching to the main Zulip application to get the latest features and bug fixes. Thank you for being a beta tester!'; |
| 150 | + |
| 151 | + unawaited(showDialog( |
| 152 | + context: context, |
| 153 | + builder: (BuildContext context) => AlertDialog( |
| 154 | + title: Text('Time to switch to the new app'), |
| 155 | + content: SingleChildScrollView(child: Text(message)), |
| 156 | + actions: [ |
| 157 | + TextButton( |
| 158 | + onPressed: () => Navigator.pop(context), |
| 159 | + child: _dialogActionText('Got it')), |
| 160 | + ...(switch (defaultTargetPlatform) { |
| 161 | + TargetPlatform.android => [ |
| 162 | + TextButton( |
| 163 | + onPressed: () { |
| 164 | + Navigator.pop(context); |
| 165 | + PlatformActions.launchUrl(context, |
| 166 | + Uri.parse('https://github.com/zulip/zulip-flutter/releases/latest')); |
| 167 | + }, |
| 168 | + child: _dialogActionText('Download official APKs (less common)')), |
| 169 | + TextButton( |
| 170 | + onPressed: () { |
| 171 | + Navigator.pop(context); |
| 172 | + PlatformActions.launchUrl(context, |
| 173 | + Uri.parse('https://play.google.com/store/apps/details?id=com.zulipmobile')); |
| 174 | + }, |
| 175 | + child: _dialogActionText('Open Google Play Store')) |
| 176 | + ], |
| 177 | + TargetPlatform.iOS => [ |
| 178 | + TextButton( |
| 179 | + onPressed: () { |
| 180 | + Navigator.pop(context); |
| 181 | + PlatformActions.launchUrl(context, |
| 182 | + Uri.parse('https://apps.apple.com/app/zulip/id1203036395')); |
| 183 | + }, |
| 184 | + child: _dialogActionText('Open App Store')), |
| 185 | + ], |
| 186 | + TargetPlatform.macOS || TargetPlatform.fuchsia |
| 187 | + || TargetPlatform.linux || TargetPlatform.windows => throw UnimplementedError(), |
| 188 | + }), |
| 189 | + ]))); |
| 190 | +} |
0 commit comments