Skip to content

Commit e58e150

Browse files
committed
Redirect macOS downloads to App Store
1 parent 6550c04 commit e58e150

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

website/lib/sections/download_section.dart

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class DownloadSection extends StatefulWidget {
1818
}
1919

2020
class _DownloadSectionState extends State<DownloadSection> {
21-
String? _macUrl;
21+
static const _macAppStoreUrl =
22+
'https://apps.apple.com/us/app/patterns-ocd-journaling/id6762611172?mt=12';
23+
2224
String? _linuxUrl;
2325
String? _version;
2426
bool _loading = true;
@@ -42,9 +44,7 @@ class _DownloadSectionState extends State<DownloadSection> {
4244
for (final asset in assets) {
4345
final name = asset['name'] as String;
4446
final url = asset['browser_download_url'] as String;
45-
if (name.endsWith('.dmg')) {
46-
_macUrl = url;
47-
} else if (name.endsWith('.deb')) {
47+
if (name.endsWith('.deb')) {
4848
_linuxUrl = url;
4949
}
5050
}
@@ -58,10 +58,19 @@ class _DownloadSectionState extends State<DownloadSection> {
5858

5959
void _download(String? assetUrl, String platform) {
6060
AnalyticsService.logDownload(platform, _version ?? 'unknown');
61-
final url = assetUrl ?? 'https://github.com/maskedsyntax/patterns/releases/latest';
61+
final url =
62+
assetUrl ?? 'https://github.com/maskedsyntax/patterns/releases/latest';
6263
launchUrl(Uri.parse(url));
6364
}
6465

66+
void _openMacAppStore() {
67+
AnalyticsService.logDownload('macOS', _version ?? 'unknown');
68+
launchUrl(
69+
Uri.parse(_macAppStoreUrl),
70+
webOnlyWindowName: '_blank',
71+
);
72+
}
73+
6574
@override
6675
Widget build(BuildContext context) {
6776
final screen = Responsive.getScreenSize(context);
@@ -114,13 +123,14 @@ class _DownloadSectionState extends State<DownloadSection> {
114123
icon: Icons.desktop_mac_rounded,
115124
format: '.dmg',
116125
description: 'macOS 12 Monterey or later',
117-
onDownload: () => _download(_macUrl, 'macOS'),
126+
buttonLabel: 'Open App Store',
127+
onDownload: _openMacAppStore,
118128
isDark: widget.isDark,
119129
accent: accent,
120130
textColor: textColor,
121131
secondaryText: secondaryText,
122132
border: border,
123-
loading: _loading,
133+
loading: false,
124134
),
125135
_DownloadCard(
126136
platform: 'Linux',
@@ -213,6 +223,7 @@ class _DownloadCard extends StatefulWidget {
213223
final IconData icon;
214224
final String format;
215225
final String description;
226+
final String? buttonLabel;
216227
final VoidCallback onDownload;
217228
final bool isDark;
218229
final Color accent;
@@ -226,6 +237,7 @@ class _DownloadCard extends StatefulWidget {
226237
required this.icon,
227238
required this.format,
228239
required this.description,
240+
this.buttonLabel,
229241
required this.onDownload,
230242
required this.isDark,
231243
required this.accent,
@@ -310,7 +322,7 @@ class _DownloadCardState extends State<_DownloadCard> {
310322
const SizedBox(width: 8),
311323
Flexible(
312324
child: Text(
313-
'Download ${widget.format}',
325+
widget.buttonLabel ?? 'Download ${widget.format}',
314326
maxLines: 1,
315327
softWrap: false,
316328
overflow: TextOverflow.ellipsis,

0 commit comments

Comments
 (0)