Skip to content

Commit c8c380b

Browse files
committed
feat: add favicon and app icons
- Update favicon to match the LogoIcon. - Serve icons from the native C web server. - Ignore generated asset headers in .gitignore.
1 parent cfba6b8 commit c8c380b

10 files changed

Lines changed: 49 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
*.o
55

66
# Generated Asset Headers
7-
include/assets_index_html.h
8-
include/assets_cache_appcache.h
9-
include/assets_cacert_pem.h
7+
include/assets_*.h
108

119
# Frontend build artifacts
1210
frontend/dist/

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ ASSET_HEADER := include/assets_index_html.h
2222
CA_HEADER := include/assets_cacert_pem.h
2323
MANIFEST_HEADER := include/assets_cache_appcache.h
2424
FRONTEND_MANIFEST := frontend/dist/cache.appcache
25+
FAVICON_SVG_HEADER := include/assets_favicon_svg.h
26+
ICON_PNG_HEADER := include/assets_icon_png.h
27+
2528

2629

2730

@@ -56,6 +59,14 @@ $(MANIFEST_HEADER): $(FRONTEND_DIST)
5659
@echo "Generating Manifest asset header..."
5760
$(PYTHON) tools/gen_assets.py $(FRONTEND_MANIFEST) $(MANIFEST_HEADER) cache_appcache
5861

62+
$(FAVICON_SVG_HEADER): $(FRONTEND_DIST)
63+
@echo "Generating Favicon SVG asset header..."
64+
$(PYTHON) tools/gen_assets.py frontend/dist/favicon.svg $(FAVICON_SVG_HEADER) favicon_svg
65+
66+
$(ICON_PNG_HEADER): $(FRONTEND_DIST)
67+
@echo "Generating Icon PNG asset header..."
68+
$(PYTHON) tools/gen_assets.py frontend/dist/icon.png $(ICON_PNG_HEADER) icon_png
69+
5970
$(CA_HEADER):
6071
@echo "Downloading CA bundle..."
6172
wget -O include/cacert.pem https://curl.se/ca/cacert.pem
@@ -67,14 +78,14 @@ $(FRONTEND_DIST):
6778
@echo "Please run 'make frontend-build' locally on your host machine first."
6879
@exit 1
6980

70-
$(ELF): $(ASSET_HEADER) $(MANIFEST_HEADER) $(CA_HEADER) $(SRCS)
81+
$(ELF): $(ASSET_HEADER) $(MANIFEST_HEADER) $(CA_HEADER) $(FAVICON_SVG_HEADER) $(ICON_PNG_HEADER) $(SRCS)
7182
@echo "Building $(ELF)..."
7283
$(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRCS) $(LIBS)
7384
@echo "Stripping $(ELF)..."
7485
$(STRIP) $(ELF)
7586

7687
clean:
77-
rm -f $(ELF) $(ASSET_HEADER) $(MANIFEST_HEADER) $(CA_HEADER) src/*.o
88+
rm -f $(ELF) $(ASSET_HEADER) $(MANIFEST_HEADER) $(CA_HEADER) $(FAVICON_SVG_HEADER) $(ICON_PNG_HEADER) src/*.o
7889

7990

8091

frontend/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<head>
55
<meta charset="UTF-8" />
66
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7+
<link rel="icon" type="image/png" href="/icon.png" />
8+
<link rel="apple-touch-icon" href="/icon.png" />
79
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
810
<title>[[TITLE_PLACEHOLDER]]</title>
911
</head>
6.01 KB
Loading

frontend/public/favicon-16x16.png

1.08 KB
Loading

frontend/public/favicon-32x32.png

1.54 KB
Loading

frontend/public/favicon.svg

Lines changed: 16 additions & 1 deletion
Loading

frontend/public/icon-192.png

6.4 KB
Loading

frontend/public/icon.png

13.5 KB
Loading

src/main.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "assets_index_html.h"
1919
#include "assets_cache_appcache.h"
20+
#include "assets_favicon_svg.h"
21+
#include "assets_icon_png.h"
2022

2123
#include "pldmgr.h"
2224

@@ -720,9 +722,10 @@ static enum MHD_Result on_request(void *cls, struct MHD_Connection *conn,
720722
}
721723
}
722724

723-
/* Only log significant requests, not pollers like /log */
725+
/* Only log significant requests, not pollers like /log or static assets */
724726
if (strcmp(url, ROUTE_LOG) != 0 && strcmp(url, ROUTE_INDEX) != 0 &&
725-
strcmp(url, ROUTE_INDEX_HTML) != 0) {
727+
strcmp(url, ROUTE_INDEX_HTML) != 0 && strcmp(url, "/favicon.svg") != 0 &&
728+
strcmp(url, "/icon.png") != 0) {
726729
pldmgr_log("[PLDMGR] Request: %s %s\n", method, url);
727730
}
728731

@@ -801,6 +804,18 @@ static enum MHD_Result on_request(void *cls, struct MHD_Connection *conn,
801804
MHD_RESPMEM_PERSISTENT);
802805
MHD_add_response_header(resp, "Content-Type", "text/cache-manifest");
803806
MHD_add_response_header(resp, "Cache-Control", "no-cache, must-revalidate");
807+
} else if (strcmp(url, "/favicon.svg") == 0) {
808+
resp = MHD_create_response_from_buffer(assets_favicon_svg_len,
809+
(void *)assets_favicon_svg,
810+
MHD_RESPMEM_PERSISTENT);
811+
MHD_add_response_header(resp, "Content-Type", "image/svg+xml");
812+
MHD_add_response_header(resp, "Cache-Control", "max-age=604800");
813+
} else if (strcmp(url, "/icon.png") == 0) {
814+
resp = MHD_create_response_from_buffer(assets_icon_png_len,
815+
(void *)assets_icon_png,
816+
MHD_RESPMEM_PERSISTENT);
817+
MHD_add_response_header(resp, "Content-Type", "image/png");
818+
MHD_add_response_header(resp, "Cache-Control", "max-age=604800");
804819
} else if (strcmp(url, ROUTE_CHECK) == 0) {
805820

806821

0 commit comments

Comments
 (0)