private List<PwaIcon> initializeIcons(BufferedImage baseImage, int bgColor) { for (PwaIcon icon : getIconTemplates(pwaConfiguration.getIconPath())) { // New image with wanted size icon.setImage(drawIconImage(baseImage, bgColor, icon)); // Store byte array and hashcode of image (GeneratedImage) icons.add(icon); } return icons; }
/** * List of {@link PwaIcon}:s that should be added to manifest.webmanifest. * * @return List of {@link PwaIcon}:s that should be added to * manifest.webmanifest */ public List<PwaIcon> getManifestIcons() { return getIcons(PwaIcon.Domain.MANIFEST); }
BufferedImage baseImage = getBaseImage(logo); icons = initializeIcons(baseImage, bgColor); offlineHtml = initializeOfflinePage(pwaConfiguration, offlinePage); offlineHash = offlineHtml.hashCode(); manifestJson = initializeManifest().toJson(); serviceWorkerJs = initializeServiceWorker(servletContext); installPrompt = initializeInstallPrompt(pwaConfiguration);
private void init() { if (!pwaRegistry.getPwaConfiguration().isEnabled()) { return; for (PwaIcon icon : pwaRegistry.getIcons()) { requestHandlerMap.put(icon.getRelHref(), (session, request, response) -> { pwaRegistry.getPwaConfiguration().relOfflinePath(), (session, request, response) -> { response.setContentType("text/html"); try (PrintWriter writer = response.getWriter()) { writer.write(pwaRegistry.getOfflineHtml()); pwaRegistry.getPwaConfiguration().relManifestPath(), (session, request, response) -> { response.setContentType("application/manifest+json"); try (PrintWriter writer = response.getWriter()) { writer.write(pwaRegistry.getManifestJson()); pwaRegistry.getPwaConfiguration().relServiceWorkerPath(), (session, request, response) -> { response.setContentType("application/javascript"); try (PrintWriter writer = response.getWriter()) { writer.write(pwaRegistry.getServiceWorkerJs());
List<String> filesToCahe = getIcons().stream() .filter(PwaIcon::shouldBeCached).map(PwaIcon::getCacheFormat) .collect(Collectors.toList()); filesToCahe.add(offlinePageCache()); filesToCahe.add(manifestCache()); .append(" .catch(function() {\n") .append(String.format(" return caches.match('%s');%n", getPwaConfiguration().getOfflinePath())) .append(" })\n );\n }\n });");
PwaConfiguration config = registry.getPwaConfiguration(); for (PwaIcon icon : registry.getHeaderIcons()) { head.appendChild(icon.asElement()); if (registry.getPwaConfiguration().isInstallPromptEnabled()) { document.body().append(registry.getInstallPrompt());
private String initializeOfflinePage(PwaConfiguration config, URL resource) throws IOException { List<PwaIcon> iconList = getIcons().stream() .filter(PwaIcon::shouldBeCached).collect(Collectors.toList()); String offlinePage = getOfflinePageFromContext(connection);
attribute = new PwaRegistry(pwa, servletContext); servletContext.setAttribute(PwaRegistry.class.getName(), attribute);
for (PwaIcon icon : getManifestIcons()) { JsonObject iconData = Json.createObject(); iconData.put("src", icon.getHref());
/** * List of {@link PwaIcon}:s that should be added to header. * * @return List of {@link PwaIcon}:s that should be added to header */ public List<PwaIcon> getHeaderIcons() { return getIcons(PwaIcon.Domain.HEADER); }
private String initializeInstallPrompt(PwaConfiguration pwaConfiguration) { PwaIcon largest = getIcons().stream().filter(PwaIcon::shouldBeCached) .min((icon1, icon2) -> icon2.getWidth() - icon1.getWidth()) .orElse(null); return BootstrapHandler.readResource("default-pwa-prompt.html") .replace("%%%INSTALL%%%", "Install") .replace("%%%LOGO_PATH%%%", largest == null ? "" : pwaConfiguration.getRootUrl() + largest.getHref()) .replace("%%%PROJECT_NAME%%%", pwaConfiguration.getAppName()); }