Skip to content

Commit 52c3c10

Browse files
committed
fix(web): route mobile invite downloads to app stores
Signed-off-by: Tom Brow <[email protected]>
1 parent b36600f commit 52c3c10

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎web/src/shared/lib/buzz-download.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
export const BUZZ_RELEASES_URL = "https://github.com/block/buzz/releases";
2+
export const BUZZ_IOS_APP_STORE_URL = "https://apps.apple.com/app/id6779728271";
3+
export const BUZZ_ANDROID_PLAY_STORE_URL =
4+
"https://play.google.com/store/apps/details?id=xyz.block.buzz.mobile";
25
const BUZZ_RELEASES_API_URL =
36
"https://api.github.com/repos/block/buzz/releases?per_page=10";
47
const CACHE_KEY = "buzz.latestDownload.v1";
58
const CACHE_TTL_MS = 60 * 60 * 1000;
69

710
export type BuzzDownloadPlatform = {
8-
operatingSystem: "linux" | "macos" | "windows" | "unknown";
11+
operatingSystem:
12+
| "linux"
13+
| "macos"
14+
| "windows"
15+
| "ios"
16+
| "android"
17+
| "unknown";
918
architecture: "arm64" | "x64" | "unknown";
1019
};
1120

@@ -36,13 +45,15 @@ function normalizeOperatingSystem(
3645

3746
// Compatibility tokens are treacherous: iPadOS can report MacIntel and a
3847
// Macintosh UA, while Android and ChromeOS expose Linux platform strings.
39-
// Reject non-desktop devices before admitting desktop-looking signals.
48+
// Classify mobile devices before admitting desktop-looking signals.
4049
const isIPadDesktopMode =
4150
platform === "macintel" && navigatorValue.maxTouchPoints > 1;
51+
if (isIPadDesktopMode || /iphone|ipad|ipod/.test(userAgent)) return "ios";
52+
if (/android/.test(userAgent) || platform === "android") return "android";
53+
4254
const isUnsupportedDevice =
4355
userAgentData?.mobile === true ||
44-
isIPadDesktopMode ||
45-
/android|iphone|ipad|ipod|mobile|tablet|windows phone|iemobile|opera mini|opera mobi|webos|blackberry|bb10|kindle|silk|kaios|cros/.test(
56+
/mobile|tablet|windows phone|iemobile|opera mini|opera mobi|webos|blackberry|bb10|kindle|silk|kaios|cros/.test(
4657
userAgent,
4758
);
4859
if (isUnsupportedDevice) return "unknown";
@@ -142,6 +153,10 @@ export function selectBuzzDownloadUrl(
142153
export async function resolveBuzzDownloadUrlForPlatform(
143154
platform: BuzzDownloadPlatform,
144155
): Promise<string> {
156+
if (platform.operatingSystem === "ios") return BUZZ_IOS_APP_STORE_URL;
157+
if (platform.operatingSystem === "android")
158+
return BUZZ_ANDROID_PLAY_STORE_URL;
159+
145160
try {
146161
const cached = JSON.parse(sessionStorage.getItem(CACHE_KEY) ?? "null") as {
147162
expiresAt: number;

‎web/tests/e2e/smoke.spec.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { createHash } from "node:crypto";
22
import { expect, test } from "@playwright/test";
3+
import {
4+
BUZZ_ANDROID_PLAY_STORE_URL,
5+
BUZZ_IOS_APP_STORE_URL,
6+
BUZZ_RELEASES_URL,
7+
} from "../../src/shared/lib/buzz-download";
38

49
test("home page loads with Buzz branding", async ({ page }) => {
510
await page.goto("/");
@@ -260,40 +265,44 @@ test("invite asks Safari users to choose their Mac download", async ({
260265
await context.close();
261266
});
262267

263-
test("invite download falls back for mobile and non-desktop devices", async ({
268+
test("invite download links to the appropriate platform destination", async ({
264269
browser,
265270
}) => {
266-
const unsupportedDevices = [
271+
const devices = [
267272
{
268273
name: "iPhone Safari",
274+
expectedUrl: BUZZ_IOS_APP_STORE_URL,
269275
platform: "iPhone",
270276
userAgent:
271277
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15",
272278
maxTouchPoints: 5,
273279
},
274280
{
275281
name: "iPadOS desktop mode",
282+
expectedUrl: BUZZ_IOS_APP_STORE_URL,
276283
platform: "MacIntel",
277284
userAgent:
278285
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15",
279286
maxTouchPoints: 5,
280287
},
281288
{
282289
name: "Android phone",
290+
expectedUrl: BUZZ_ANDROID_PLAY_STORE_URL,
283291
platform: "Linux armv8l",
284292
userAgent:
285293
"Mozilla/5.0 (Linux; Android 15; Pixel 9 Pro) AppleWebKit/537.36 Mobile",
286294
maxTouchPoints: 5,
287295
},
288296
{
289297
name: "ChromeOS",
298+
expectedUrl: BUZZ_RELEASES_URL,
290299
platform: "Linux x86_64",
291300
userAgent: "Mozilla/5.0 (X11; CrOS x86_64 16093.68.0) AppleWebKit/537.36",
292301
maxTouchPoints: 0,
293302
},
294303
];
295304

296-
for (const device of unsupportedDevices) {
305+
for (const device of devices) {
297306
const context = await browser.newContext({ userAgent: device.userAgent });
298307
await context.addInitScript(({ platform, maxTouchPoints }) => {
299308
Object.defineProperties(navigator, {
@@ -343,7 +352,7 @@ test("invite download falls back for mobile and non-desktop devices", async ({
343352
await expect(
344353
page.getByRole("link", { name: "Download it now" }),
345354
device.name,
346-
).toHaveAttribute("href", "https://github.com/block/buzz/releases");
355+
).toHaveAttribute("href", device.expectedUrl);
347356
await context.close();
348357
}
349358
});

0 commit comments

Comments
 (0)