Skip to content

Commit 7edfcb6

Browse files
committed
UY-1256 add & document user control of favicon, add default ones
1 parent eae0fc1 commit 7edfcb6

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

documentation/src/main/doc/branding-v2x.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,17 @@ Example panel with a simple header added:
8383
----
8484

8585

86+
==== Controlling favicon
87+
88+
Configuration of favicon shall be provided in a file located in the default web contents directory (which is by default the +webContents/+
89+
directory of distribution), in a file under path: +VAADIN/favicon.html+.
90+
91+
The file may look like the default one found in Unity's distribution:
92+
93+
----
94+
<link rel="icon" type="image/png" sizes="16x16" href="./VAADIN/themes/common/img/favicon/favicon-16.png">
95+
<link rel="icon" type="image/png" sizes="24x24" href="./VAADIN/themes/common/img/favicon/favicon-24.png">
96+
----
97+
98+
Note that contents of this file will be placed as-is in the HTML header section of the web pages generated by Unity.
99+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<link rel="icon" type="image/png" sizes="16x16" href="./VAADIN/themes/common/img/favicon/favicon-16.png">
2+
<link rel="icon" type="image/png" sizes="24x24" href="./VAADIN/themes/common/img/favicon/favicon-24.png">
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<link rel="icon" type="image/png" sizes="16x16" href="./VAADIN/themes/common/img/favicon/favicon-16.png">
2+
<link rel="icon" type="image/png" sizes="24x24" href="./VAADIN/themes/common/img/favicon/favicon-24.png">

web-upman/src/main/java/io/imunity/upman/front/UnityShellConfigurator.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,66 @@
55

66
package io.imunity.upman.front;
77

8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
13+
import org.apache.logging.log4j.Logger;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
816
import com.vaadin.flow.component.page.AppShellConfigurator;
17+
import com.vaadin.flow.component.page.Inline.Wrapping;
918
import com.vaadin.flow.component.page.Push;
1019
import com.vaadin.flow.server.AppShellSettings;
1120
import com.vaadin.flow.shared.ui.Transport;
1221
import com.vaadin.flow.theme.Theme;
1322
import com.vaadin.flow.theme.lumo.Lumo;
1423

24+
import pl.edu.icm.unity.base.utils.Log;
25+
import pl.edu.icm.unity.engine.api.config.UnityServerConfiguration;
26+
1527
@Push(transport = Transport.LONG_POLLING)
1628
@Theme(themeClass = Lumo.class)
1729
public class UnityShellConfigurator implements AppShellConfigurator
1830
{
31+
private static final Logger log = Log.getLogger(Log.U_SERVER_WEB, UnityShellConfigurator.class);
32+
private final UnityServerConfiguration config;
33+
34+
35+
@Autowired
36+
UnityShellConfigurator(UnityServerConfiguration config)
37+
{
38+
this.config = config;
39+
}
40+
1941
@Override
2042
public void configurePage(AppShellSettings settings)
2143
{
22-
settings.addLink("shortcut icon", "/unitygw/VAADIN/favicon.ico");
44+
setupFavicon(settings);
45+
}
46+
47+
private void setupFavicon(AppShellSettings settings)
48+
{
49+
File webContentsFile = config.getFileValue(UnityServerConfiguration.DEFAULT_WEB_CONTENT_PATH, true);
50+
Path faviconDefFile = webContentsFile.toPath().resolve(Path.of("VAADIN", "favicon.html"));
51+
log.debug("Trying to read favicon definitions from {}", faviconDefFile);
52+
if (Files.isReadable(faviconDefFile))
53+
{
54+
String faviconDefContents = readFile(faviconDefFile);
55+
log.debug("Installing favicon definition from {}", faviconDefFile);
56+
settings.addInlineWithContents(faviconDefContents, Wrapping.NONE);
57+
}
58+
}
59+
60+
private String readFile(Path faviconDefFile)
61+
{
62+
try
63+
{
64+
return Files.readString(faviconDefFile);
65+
} catch (IOException e)
66+
{
67+
throw new IllegalStateException("Unable to read favicon file " + faviconDefFile, e);
68+
}
2369
}
2470
}

0 commit comments

Comments
 (0)