Skip to content

Commit 78d9bcd

Browse files
matt2eclaude
andcommitted
feat(desktop): open this machine's installer from the banner's download button
the deprecation banner's "Get the new app" button now opens the new app's installer for the running machine when it can, and https://buzz.xyz otherwise. the label, icon, outline style and accessible name are unchanged. how it resolves the installer: - a new tauri command, new_app_installer_target, reports the install's key in the block/buzz-app installer manifest: macos-arm64, macos-x64, windows-x64, linux-appimage or linux-deb. linux reports the appimage key when APPIMAGE is set, the deb key only when it is unset and /usr/bin/dpkg exists, and no key otherwise. no other os or architecture gets a key. there is no rosetta detection, so an intel build on apple silicon gets the intel installer. - when the banner mounts visible and the command returned a key, the webview fetches https://raw.githubusercontent.com/block/buzz-app/download-feed/downloads.json once, with a 5 second timeout. dismissing the banner aborts it. - resolveInstallerUrl in the new src/app/newAppInstaller.ts accepts an entry only when schemaVersion is 1, channel is "stable", the entry is a string, and its parsed url is https://github.com with no credentials, a path under /block/buzz-app/releases/download/ and the file extension that key installs. - the click handler stays synchronous. it opens the resolved url if there is one and https://buzz.xyz if not, so it never waits on the fetch. a missing key, a failed or slow fetch and a rejected manifest all leave the fallback in place; failures log one console warning and are not retried until the next launch. the link still goes through the opener plugin's openUrl, and the default browser performs the download. the csp already allows https connect-src and opener:default already allows https urls, so neither config changes. the button carries data-download-source="installer" or "fallback" so specs can wait on the resolution. the e2e mock bridge answers the new command from mock.newAppInstallerTarget and defaults to no key, so no spec fetches the manifest unless it opts in. tests added: - rust: a table test for the key mapping. - unit: newAppInstaller.test.mjs covers the five valid keys and each rejection rule. - smoke: the existing banner journey asserts the fallback url on the default mock. one new test fulfils the manifest route and checks the click opens the arm64 dmg url. another holds the route pending, checks the click opens buzz.xyz at once, then releases it and checks the button switches to the installer. checks that ran and passed: - desktop `pnpm check` (biome, px-text, pubkey-truncation), `pnpm typecheck` and `pnpm check:file-sizes`. - desktop `pnpm test` under the repo's pinned node 24.15.0: 6956 and 185 tests, 0 failures, including the new resolver tests. - `cargo test --manifest-path desktop/src-tauri/Cargo.toml --lib installer_target_key` on rust 1.98.1: 1 passed. this is the new helper's test only, not the whole tauri crate suite. - `cargo clippy --manifest-path desktop/src-tauri/Cargo.toml --all-targets -- -D warnings` and `cargo fmt --check` for the same crate. - tests/e2e/deprecation-banner.spec.ts on an e2e build: 3 passed. - falsification: with the path-prefix check removed, the unit rejection table fails on "another repository". with the banner effect disabled, both new smoke tests fail with the button still on "fallback". both edits were reverted. not run or not finished: - the full `pnpm test:e2e:smoke` run was still going at commit time, at test 1208 of 1496 on one worker. so far 1207 passed and 1 failed. the three banner tests passed in that run. - the one failure is test 814, tests/e2e/mentions.spec.ts:4595 "mention text is highlighted in sent messages". the sent row reads "Hey @bobcheck this out ...": the typed suffix landed against the mention without its separator space, so no mention chip rendered. the banner is seeded dismissed in that spec and is absent from the failure snapshot, and with no installer key the new effect does nothing, so this change does not look like the cause. it reads as the composer's caret timing after autocomplete. it was not rerun, so that judgement is from the error text alone. - `just ci` was not run, because it rebuilds the desktop output the smoke run is serving. the whole tauri crate test suite, the root workspace tests, the web build and the mobile tests were therefore not run either. - the fetch was not exercised in the native app window. playwright runs in plain chromium without the tauri csp, so nothing here proves the webview can reach the manifest or that the browser downloads the right installer. that needs a person: launch a build on macos, click "Get the new app", and confirm the matching dmg downloads. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 5498a00 commit 78d9bcd

9 files changed

Lines changed: 411 additions & 2 deletions

File tree

‎desktop/src-tauri/src/commands/updater.rs‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,69 @@ pub fn is_auto_update_supported() -> bool {
2222
true
2323
}
2424
}
25+
26+
/// Maps a platform to its key in the new Buzz app's installer manifest, or
27+
/// `None` when no installer is published for it.
28+
///
29+
/// On Linux a missing `APPIMAGE` variable only means "not an AppImage", so
30+
/// the deb key also requires dpkg; a source build on another distro gets no
31+
/// key instead of a package it cannot install.
32+
fn installer_target_key(
33+
os: &str,
34+
arch: &str,
35+
is_appimage: bool,
36+
has_dpkg: bool,
37+
) -> Option<&'static str> {
38+
match (os, arch) {
39+
("macos", "aarch64") => Some("macos-arm64"),
40+
("macos", "x86_64") => Some("macos-x64"),
41+
("windows", "x86_64") => Some("windows-x64"),
42+
("linux", "x86_64") if is_appimage => Some("linux-appimage"),
43+
("linux", "x86_64") if has_dpkg => Some("linux-deb"),
44+
_ => None,
45+
}
46+
}
47+
48+
/// Returns the running install's key in the new Buzz app's installer
49+
/// manifest, or `None` when the frontend should link to the website instead.
50+
#[tauri::command]
51+
pub fn new_app_installer_target() -> Option<&'static str> {
52+
installer_target_key(
53+
std::env::consts::OS,
54+
std::env::consts::ARCH,
55+
std::env::var_os("APPIMAGE").is_some(),
56+
std::path::Path::new("/usr/bin/dpkg").exists(),
57+
)
58+
}
59+
60+
#[cfg(test)]
61+
mod tests {
62+
use super::installer_target_key;
63+
64+
#[test]
65+
fn installer_target_key_covers_each_shipped_target_and_nothing_else() {
66+
// (os, arch, is_appimage, has_dpkg, expected)
67+
let cases = [
68+
("macos", "aarch64", false, false, Some("macos-arm64")),
69+
("macos", "x86_64", false, false, Some("macos-x64")),
70+
("windows", "x86_64", false, false, Some("windows-x64")),
71+
("linux", "x86_64", true, false, Some("linux-appimage")),
72+
// An AppImage on a Debian host is still an AppImage.
73+
("linux", "x86_64", true, true, Some("linux-appimage")),
74+
("linux", "x86_64", false, true, Some("linux-deb")),
75+
// Source build on a distro without dpkg.
76+
("linux", "x86_64", false, false, None),
77+
// No arm64 Linux or Windows installer is published.
78+
("linux", "aarch64", true, true, None),
79+
("windows", "aarch64", false, false, None),
80+
("freebsd", "x86_64", false, true, None),
81+
];
82+
for (os, arch, is_appimage, has_dpkg, expected) in cases {
83+
assert_eq!(
84+
installer_target_key(os, arch, is_appimage, has_dpkg),
85+
expected,
86+
"{os}/{arch} appimage={is_appimage} dpkg={has_dpkg}"
87+
);
88+
}
89+
}
90+
}

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ pub fn run() {
874874
archive::sync::start_archive_sync,
875875
archive::sync::stop_archive_sync,
876876
is_auto_update_supported,
877+
new_app_installer_target,
877878
set_window_vibrancy,
878879
#[cfg(target_os = "macos")]
879880
tray_menu::clear_tray_agent_activity,

‎desktop/src/app/DeprecationBanner.tsx‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ import {
66
DEPRECATION_BANNER_STORAGE_KEY,
77
shouldShowDeprecationBanner,
88
} from "@/app/deprecationBannerVisibility";
9+
import {
10+
BUZZ_APP_DOWNLOADS_MANIFEST_URL,
11+
NEW_APP_MANIFEST_TIMEOUT_MS,
12+
resolveInstallerUrl,
13+
} from "@/app/newAppInstaller";
14+
import { getNewAppInstallerTarget } from "@/shared/api/tauri";
915
import { Button } from "@/shared/ui/button";
1016

11-
const BUZZ_WEBSITE_URL = "https://buzz.xyz";
17+
// Opened until, and unless, the installer for this machine is resolved.
18+
const BUZZ_APP_FALLBACK_URL = "https://buzz.xyz";
1219
const BUZZ_APP_UPGRADE_GUIDE_URL =
1320
"https://github.com/block/buzz-app/blob/main/docs/upgrading.md";
1421

@@ -23,10 +30,62 @@ function readDismissedAt(): string | null {
2330
}
2431
}
2532

33+
/**
34+
* Looks up the new app's installer for this machine. Rejects on any failure;
35+
* resolves null when no installer is published for this platform.
36+
*/
37+
async function fetchInstallerUrl(signal: AbortSignal): Promise<string | null> {
38+
const target = await getNewAppInstallerTarget();
39+
if (!target) {
40+
return null;
41+
}
42+
const response = await fetch(BUZZ_APP_DOWNLOADS_MANIFEST_URL, { signal });
43+
if (!response.ok) {
44+
throw new Error(`installer manifest responded ${response.status}`);
45+
}
46+
const url = resolveInstallerUrl(await response.json(), target);
47+
if (!url) {
48+
throw new Error(`installer manifest has no usable entry for ${target}`);
49+
}
50+
return url;
51+
}
52+
2653
export function DeprecationBanner() {
2754
const [isVisible, setIsVisible] = React.useState(() =>
2855
shouldShowDeprecationBanner(readDismissedAt(), Date.now()),
2956
);
57+
const [installerUrl, setInstallerUrl] = React.useState<string | null>(null);
58+
59+
// One attempt per mount. The click never waits on it: until it resolves,
60+
// and whenever it fails, the button opens the fallback page.
61+
React.useEffect(() => {
62+
if (!isVisible) {
63+
return;
64+
}
65+
let isCurrent = true;
66+
const controller = new AbortController();
67+
const timeout = window.setTimeout(
68+
() => controller.abort(new Error("installer manifest timed out")),
69+
NEW_APP_MANIFEST_TIMEOUT_MS,
70+
);
71+
fetchInstallerUrl(controller.signal)
72+
.then((url) => {
73+
if (isCurrent) {
74+
setInstallerUrl(url);
75+
}
76+
})
77+
.catch((error: unknown) => {
78+
if (isCurrent) {
79+
console.warn("Could not resolve the new app installer:", error);
80+
}
81+
})
82+
.finally(() => window.clearTimeout(timeout));
83+
return () => {
84+
isCurrent = false;
85+
window.clearTimeout(timeout);
86+
controller.abort();
87+
};
88+
}, [isVisible]);
3089

3190
if (!isVisible) {
3291
return null;
@@ -76,9 +135,10 @@ export function DeprecationBanner() {
76135
</Button>
77136
<Button
78137
className={BANNER_ACTION_CLASS}
138+
data-download-source={installerUrl ? "installer" : "fallback"}
79139
data-testid="deprecation-banner-download"
80140
onClick={() => {
81-
void openUrl(BUZZ_WEBSITE_URL);
141+
void openUrl(installerUrl ?? BUZZ_APP_FALLBACK_URL);
82142
}}
83143
size="sm"
84144
type="button"
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { resolveInstallerUrl } from "./newAppInstaller.ts";
5+
6+
const RELEASE = "https://github.com/block/buzz-app/releases/download/v1.0.0";
7+
const DOWNLOADS = {
8+
"macos-arm64": `${RELEASE}/Buzz_1.0.0_aarch64.dmg`,
9+
"macos-x64": `${RELEASE}/Buzz_1.0.0_x64.dmg`,
10+
"windows-x64": `${RELEASE}/Buzz_1.0.0_x64_unsigned.exe`,
11+
"linux-appimage": `${RELEASE}/Buzz_1.0.0_x86_64.AppImage`,
12+
"linux-deb": `${RELEASE}/Buzz_1.0.0_amd64.deb`,
13+
};
14+
15+
function manifest(overrides = {}) {
16+
return {
17+
schemaVersion: 1,
18+
channel: "stable",
19+
version: "1.0.0",
20+
release: "v1.0.0",
21+
downloads: DOWNLOADS,
22+
...overrides,
23+
};
24+
}
25+
26+
function withDownload(url) {
27+
return manifest({ downloads: { ...DOWNLOADS, "macos-arm64": url } });
28+
}
29+
30+
test("resolves the installer for every shipped target", () => {
31+
for (const [target, url] of Object.entries(DOWNLOADS)) {
32+
assert.equal(resolveInstallerUrl(manifest(), target), url, target);
33+
}
34+
});
35+
36+
test("rejects every manifest or entry that is not a buzz-app release asset", () => {
37+
const cases = [
38+
["manifest is not an object", "not json", "macos-arm64"],
39+
["manifest is null", null, "macos-arm64"],
40+
["newer schema version", manifest({ schemaVersion: 2 }), "macos-arm64"],
41+
[
42+
"schema version as a string",
43+
manifest({ schemaVersion: "1" }),
44+
"macos-arm64",
45+
],
46+
["other channel", manifest({ channel: "beta" }), "macos-arm64"],
47+
["downloads missing", manifest({ downloads: undefined }), "macos-arm64"],
48+
[
49+
"target missing from downloads",
50+
manifest({ downloads: { "macos-x64": DOWNLOADS["macos-x64"] } }),
51+
"macos-arm64",
52+
],
53+
["target unknown to this app", manifest(), "linux-arm64"],
54+
["target that is an inherited property", manifest(), "constructor"],
55+
["entry is not a string", withDownload(42), "macos-arm64"],
56+
["entry is not a URL", withDownload("Buzz.dmg"), "macos-arm64"],
57+
[
58+
"plain http",
59+
withDownload(DOWNLOADS["macos-arm64"].replace("https:", "http:")),
60+
"macos-arm64",
61+
],
62+
[
63+
"another host",
64+
withDownload(
65+
"https://example.org/block/buzz-app/releases/download/v1.0.0/Buzz.dmg",
66+
),
67+
"macos-arm64",
68+
],
69+
[
70+
"host hidden behind userinfo",
71+
withDownload(
72+
"https://[email protected]/block/buzz-app/releases/download/v1.0.0/Buzz.dmg",
73+
),
74+
"macos-arm64",
75+
],
76+
[
77+
"credentials in the URL",
78+
withDownload(
79+
"https://user:[email protected]/block/buzz-app/releases/download/v1.0.0/Buzz.dmg",
80+
),
81+
"macos-arm64",
82+
],
83+
[
84+
"non-default port",
85+
withDownload(
86+
"https://github.com:8443/block/buzz-app/releases/download/v1.0.0/Buzz.dmg",
87+
),
88+
"macos-arm64",
89+
],
90+
[
91+
"another repository",
92+
withDownload(
93+
"https://github.com/example-org/buzz-app/releases/download/v1.0.0/Buzz.dmg",
94+
),
95+
"macos-arm64",
96+
],
97+
[
98+
"dot segments that leave the repository",
99+
withDownload(
100+
"https://github.com/block/buzz-app/releases/download/../../../../example-org/other/releases/download/v1/Buzz.dmg",
101+
),
102+
"macos-arm64",
103+
],
104+
[
105+
"encoded dot segments that leave the repository",
106+
withDownload(
107+
"https://github.com/block/buzz-app/releases/download/%2e%2e/%2e%2e/%2e%2e/%2e%2e/example-org/other/Buzz.dmg",
108+
),
109+
"macos-arm64",
110+
],
111+
[
112+
"wrong file type for the target",
113+
withDownload(DOWNLOADS["windows-x64"]),
114+
"macos-arm64",
115+
],
116+
[
117+
"expected extension only in the query",
118+
withDownload(`${RELEASE}/Buzz_1.0.0_x64_unsigned.exe?name=Buzz.dmg`),
119+
"macos-arm64",
120+
],
121+
];
122+
for (const [name, input, target] of cases) {
123+
assert.equal(resolveInstallerUrl(input, target), null, name);
124+
}
125+
});

‎desktop/src/app/newAppInstaller.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/** Installer manifest the block/buzz-app release job publishes per stable release. */
2+
export const BUZZ_APP_DOWNLOADS_MANIFEST_URL =
3+
"https://raw.githubusercontent.com/block/buzz-app/download-feed/downloads.json";
4+
export const BUZZ_APP_DOWNLOAD_PATH_PREFIX =
5+
"/block/buzz-app/releases/download/";
6+
export const NEW_APP_MANIFEST_TIMEOUT_MS = 5_000;
7+
8+
const BUZZ_APP_DOWNLOAD_ORIGIN = "https://github.com";
9+
10+
/** The file extension each manifest key must point at. */
11+
const INSTALLER_EXTENSION_BY_TARGET: Record<string, string> = {
12+
"macos-arm64": ".dmg",
13+
"macos-x64": ".dmg",
14+
"windows-x64": ".exe",
15+
"linux-appimage": ".AppImage",
16+
"linux-deb": ".deb",
17+
};
18+
19+
function isRecord(value: unknown): value is Record<string, unknown> {
20+
return typeof value === "object" && value !== null;
21+
}
22+
23+
/**
24+
* Returns the installer URL the manifest lists for `target`, or null when the
25+
* manifest or the entry is anything other than a stable-channel release asset
26+
* of block/buzz-app with the file type that target installs.
27+
*/
28+
export function resolveInstallerUrl(
29+
manifest: unknown,
30+
target: string,
31+
): string | null {
32+
if (!Object.hasOwn(INSTALLER_EXTENSION_BY_TARGET, target)) {
33+
return null;
34+
}
35+
if (
36+
!isRecord(manifest) ||
37+
manifest.schemaVersion !== 1 ||
38+
manifest.channel !== "stable" ||
39+
!isRecord(manifest.downloads) ||
40+
!Object.hasOwn(manifest.downloads, target)
41+
) {
42+
return null;
43+
}
44+
const entry = manifest.downloads[target];
45+
if (typeof entry !== "string") {
46+
return null;
47+
}
48+
49+
let url: URL;
50+
try {
51+
url = new URL(entry);
52+
} catch {
53+
return null;
54+
}
55+
// Checked on the parsed URL, so `..` segments, backslashes and userinfo
56+
// tricks are normalised before the origin and path are compared.
57+
if (
58+
url.origin !== BUZZ_APP_DOWNLOAD_ORIGIN ||
59+
url.username !== "" ||
60+
url.password !== "" ||
61+
!url.pathname.startsWith(BUZZ_APP_DOWNLOAD_PATH_PREFIX) ||
62+
!url.pathname.endsWith(INSTALLER_EXTENSION_BY_TARGET[target])
63+
) {
64+
return null;
65+
}
66+
return url.href;
67+
}

‎desktop/src/shared/api/tauri.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,9 @@ export const setPreventSleepActive = (active: boolean) =>
10631063
export function isAutoUpdateSupported(): Promise<boolean> {
10641064
return invokeTauri<boolean>("is_auto_update_supported");
10651065
}
1066+
1067+
/** Returns this install's key in the new Buzz app's installer manifest
1068+
* (e.g. `macos-arm64`), or null when no installer is published for it. */
1069+
export function getNewAppInstallerTarget(): Promise<string | null> {
1070+
return invokeTauri<string | null>("new_app_installer_target");
1071+
}

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ type E2eConfig = {
499499
* Linux .deb install where Tauri's updater cannot swap the binary).
500500
* Defaults to true for all existing tests. */
501501
autoUpdateSupported?: boolean;
502+
/** Manifest key `new_app_installer_target` returns. Defaults to none, so
503+
* the deprecation banner never fetches the installer manifest. */
504+
newAppInstallerTarget?: string;
502505
/** Reject `plugin:opener|open_url` to exercise browser-return fallback UI. */
503506
openerError?: string;
504507
/** Delay binding signatures so specs can exercise request supersession. */
@@ -14882,6 +14885,8 @@ export function maybeInstallE2eTauriMocks() {
1488214885
// Default true so all existing tests continue to use the auto-update
1488314886
// path. Set mock.autoUpdateSupported: false to simulate a .deb install.
1488414887
return activeConfig?.mock?.autoUpdateSupported !== false;
14888+
case "new_app_installer_target":
14889+
return activeConfig?.mock?.newAppInstallerTarget ?? null;
1488514890
case "relay_reconnect_hook":
1488614891
return null;
1488714892
case "relay_reconnect_hook_configured":

0 commit comments

Comments
 (0)