GITv

Make the web browser installable as an app

Browse files

Serve a web app manifest and PNG app icons (192, 512, maskable, and an Apple touch icon) from the public routes, so browsers offer to install GITv from any page, the sign-in page included. Allow the manifest in the Content-Security-Policy with manifest-src 'self', and colour the title bar to match the top bar in light and dark mode. No service worker: the site stays script-free. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Author
Um9i vulgarmessiah@gmail.com
Date
22 Nov 2026, 21:21
Commit
e6e0b2343944
Parent
9c80326

7 files changed +50−1

Binary file changed.

Binary file changed.

Binary file changed.

Binary file changed.

@@ -35,6 +35,12 @@ const STYLESHEET: &str = include_str!("../assets/style.css");
const FONT_DISPLAY: &[u8] = include_bytes!("../assets/fonts/display.woff2");
const FONT_TEXT: &[u8] = include_bytes!("../assets/fonts/text.woff2");
const FONT_MONO: &[u8] = include_bytes!("../assets/fonts/mono.woff2");
const ICON_192: &[u8] = include_bytes!("../assets/icons/192.png");
const ICON_512: &[u8] = include_bytes!("../assets/icons/512.png");
const ICON_MASKABLE: &[u8] = include_bytes!("../assets/icons/maskable.png");
const ICON_APPLE: &[u8] = include_bytes!("../assets/icons/apple-touch.png");
/// Lets browsers install GITv as an app that opens in its own window.
const MANIFEST: &str = r##"{"id":"/","name":"GITv","short_name":"GITv","start_url":"/","scope":"/","display":"standalone","background_color":"#f6f7f9","theme_color":"#ffffff","icons":[{"src":"/favicon.svg","sizes":"any","type":"image/svg+xml"},{"src":"/icons/192.png","sizes":"192x192","type":"image/png"},{"src":"/icons/512.png","sizes":"512x512","type":"image/png"},{"src":"/icons/maskable.png","sizes":"512x512","type":"image/png","purpose":"maskable"}]}"##;
const FAVICON: &str = r##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="8" fill="#0f6b5f"/><g fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round"><circle cx="11" cy="9" r="2.6"/><circle cx="11" cy="23" r="2.6"/><circle cx="22" cy="12" r="2.6"/><path d="M11 11.6v8.8M22 14.6c0 4-3.4 5-11 6"/></g></svg>"##;
/// The stylesheet's URL carries a hash of its contents, so browsers can cache it for good and
@@ -89,7 +95,7 @@ enum View {
const SECURITY: [(header::HeaderName, &str); 4] = [
(
header::CONTENT_SECURITY_POLICY,
"default-src 'none'; style-src 'self'; font-src 'self'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
"default-src 'none'; style-src 'self'; font-src 'self'; img-src 'self'; manifest-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
),
(header::X_CONTENT_TYPE_OPTIONS, "nosniff"),
(header::REFERRER_POLICY, "no-referrer"),
@@ -211,6 +217,14 @@ fn serve(port: u16) -> Result<(), String> {
let public = Router::new()
.route("/style.css", get(|| async { stylesheet() }))
.route("/favicon.svg", get(|| async { static_file("image/svg+xml", FAVICON.as_bytes()) }))
.route(
"/manifest.webmanifest",
get(|| async { static_file("application/manifest+json", MANIFEST.as_bytes()) }),
)
.route("/icons/192.png", get(|| async { static_file("image/png", ICON_192) }))
.route("/icons/512.png", get(|| async { static_file("image/png", ICON_512) }))
.route("/icons/maskable.png", get(|| async { static_file("image/png", ICON_MASKABLE) }))
.route("/apple-touch-icon.png", get(|| async { static_file("image/png", ICON_APPLE) }))
.route("/fonts/display.woff2", get(|| async { static_file("font/woff2", FONT_DISPLAY) }))
.route("/fonts/text.woff2", get(|| async { static_file("font/woff2", FONT_TEXT) }))
.route("/fonts/mono.woff2", get(|| async { static_file("font/woff2", FONT_MONO) }))
@@ -2,6 +2,8 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{{ title }} | GITv</title>
<link rel="stylesheet" href="{{ super::STYLE_URL.as_str() }}"><link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="manifest" href="/manifest.webmanifest"><link rel="apple-touch-icon" href="/apple-touch-icon.png">
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#171c22" media="(prefers-color-scheme: dark)">
<link rel="preload" href="/fonts/display.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/fonts/text.woff2" as="font" type="font/woff2" crossorigin></head>
<body><a class="skip" href="#main">Skip to content</a>
@@ -311,6 +311,11 @@ fn static_assets_are_served_and_the_stylesheet_is_versioned() {
("/fonts/display.woff2", "font/woff2"),
("/fonts/text.woff2", "font/woff2"),
("/fonts/mono.woff2", "font/woff2"),
("/manifest.webmanifest", "application/manifest+json"),
("/icons/192.png", "image/png"),
("/icons/512.png", "image/png"),
("/icons/maskable.png", "image/png"),
("/apple-touch-icon.png", "image/png"),
] {
let asset = s.get(path);
assert_eq!((asset.status, asset.header("content-type")), (200, kind), "{path}");
@@ -318,6 +323,34 @@ fn static_assets_are_served_and_the_stylesheet_is_versioned() {
}
}
#[test]
fn the_browser_can_install_gitv_as_an_app() {
let s = server();
let page = s.get_signed_out("/login");
assert!(page.header("content-security-policy").contains("manifest-src 'self'"));
let html = page.text();
assert!(html.contains(r#"<link rel="manifest" href="/manifest.webmanifest">"#), "{html}");
assert!(html.contains(r#"<link rel="apple-touch-icon" href="/apple-touch-icon.png">"#), "{html}");
let manifest = s.get_signed_out("/manifest.webmanifest");
assert_eq!(manifest.status, 200, "signed-out visitors can install from the sign-in page");
let json = manifest.text();
for field in [
r#""name":"GITv""#,
r#""start_url":"/""#,
r#""display":"standalone""#,
r#""sizes":"192x192""#,
r#""sizes":"512x512""#,
] {
assert!(json.contains(field), "{field} in {json}");
}
for src in json.split(r#""src":""#).skip(1).map(|rest| &rest[..rest.find('"').unwrap()]) {
let file = s.get_signed_out(src);
assert_eq!(file.status, 200, "{src}");
assert!(file.header("content-type").starts_with("image/"), "{src}");
}
}
#[test]
fn repository_root_redirects_to_the_tree() {
let s = server();