diff --git a/src/main.rs b/src/main.rs index b67445a..30b479a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,21 @@ async fn style() -> HttpResponse { HttpResponse::Ok().content_type("text/css").body(include_str!("../static/style.css")) } +// Required for creating a PWA +async fn manifest() -> HttpResponse { + HttpResponse::Ok().content_type("application/json").body(include_str!("../static/manifest.json")) +} + +// Required for the manifest to be valid +async fn pwa_logo() -> HttpResponse { + HttpResponse::Ok().content_type("image/png").body(include_bytes!("../static/logo.png").as_ref()) +} + +// Required for iOS App Icons +async fn iphone_logo() -> HttpResponse { + HttpResponse::Ok().content_type("image/png").body(include_bytes!("../static/touch-icon-iphone.png").as_ref()) +} + async fn robots() -> HttpResponse { HttpResponse::Ok() .header("Cache-Control", "public, max-age=1209600, s-maxage=86400") @@ -75,7 +90,7 @@ async fn main() -> std::io::Result<()> { .header("X-Frame-Options", "DENY") .header( "Content-Security-Policy", - "default-src 'none'; media-src 'self'; style-src 'self' 'unsafe-inline'; base-uri 'none'; img-src 'self' data:; form-action 'self'; frame-ancestors 'none';", + "default-src 'none'; manifest-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; base-uri 'none'; img-src 'self' data:; form-action 'self'; frame-ancestors 'none';", ), ) // Default service in case no routes match @@ -84,6 +99,9 @@ async fn main() -> std::io::Result<()> { .route("/style.css/", web::get().to(style)) .route("/favicon.ico/", web::get().to(favicon)) .route("/robots.txt/", web::get().to(robots)) + .route("/manifest.json/", web::get().to(manifest)) + .route("/logo.png/", web::get().to(pwa_logo)) + .route("/touch-icon-iphone.png/", web::get().to(iphone_logo)) // Proxy media through Libreddit .route("/proxy/{url:.*}/", web::get().to(proxy::handler)) // Browse user profile diff --git a/static/logo.png b/static/logo.png new file mode 100644 index 0000000..bd005fc Binary files /dev/null and b/static/logo.png differ diff --git a/static/manifest.json b/static/manifest.json new file mode 100644 index 0000000..4f02724 --- /dev/null +++ b/static/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "Libreddit", + "short_name": "Libreddit", + "display": "standalone", + "background_color": "#2A3443", + "description": "An alternative private front-end to Reddit", + "theme_color": "#2A3443", + "icons": [ + { + "src": "./logo.png", + "sizes": "512x512", + "type": "image/png" + } + ] + } \ No newline at end of file diff --git a/static/touch-icon-iphone.png b/static/touch-icon-iphone.png new file mode 100644 index 0000000..1b9b4d5 Binary files /dev/null and b/static/touch-icon-iphone.png differ diff --git a/templates/base.html b/templates/base.html index cbf4b3e..6400ebd 100644 --- a/templates/base.html +++ b/templates/base.html @@ -6,6 +6,19 @@ + + + + + + + + + + + + + {% endblock %}