new PwaIcon(144, 144, baseName, PwaIcon.Domain.MANIFEST, true)); icons.add( new PwaIcon(192, 192, baseName, PwaIcon.Domain.MANIFEST, true)); icons.add( new PwaIcon(512, 512, baseName, PwaIcon.Domain.MANIFEST, true)); icons.add(new PwaIcon(16, 16, baseName, PwaIcon.Domain.HEADER, true, "shortcut icon", "")); icons.add(new PwaIcon(32, 32, baseName)); icons.add(new PwaIcon(96, 96, baseName)); icons.add(new PwaIcon(180, 180, baseName, PwaIcon.Domain.HEADER, false, "apple-touch-icon", "")); icons.add(new PwaIcon(1125, 2436, baseName, PwaIcon.Domain.HEADER, false, APPLE_STARTUP_IMAGE, String.format(APPLE_IMAGE_MEDIA, 375, 812, 3))); icons.add(new PwaIcon(750, 1334, baseName, PwaIcon.Domain.HEADER, false, APPLE_STARTUP_IMAGE, String.format(APPLE_IMAGE_MEDIA, 375, 667, 2))); icons.add(new PwaIcon(1242, 2208, baseName, PwaIcon.Domain.HEADER, false, APPLE_STARTUP_IMAGE, String.format(APPLE_IMAGE_MEDIA, 414, 763, 3))); icons.add(new PwaIcon(640, 1136, baseName, PwaIcon.Domain.HEADER, false, APPLE_STARTUP_IMAGE, String.format(APPLE_IMAGE_MEDIA, 320, 568, 2)));
private List<PwaIcon> getIcons(PwaIcon.Domain domain) { return icons.stream().filter(icon -> icon.getDomain().equals(domain)) .collect(Collectors.toList()); }
private BufferedImage drawIconImage(BufferedImage baseImage, int bgColor, PwaIcon icon) { BufferedImage bimage = new BufferedImage(icon.getWidth(), icon.getHeight(), BufferedImage.TYPE_INT_ARGB); graphics.clearRect(0, 0, icon.getWidth(), icon.getHeight()); / (float) icon.getWidth() > (float) baseImage.getHeight() / (float) icon.getHeight() ? (float) baseImage.getWidth() / (float) icon.getWidth() : (float) baseImage.getHeight() / (float) icon.getHeight(); baseImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), (icon.getWidth() - newWidth) / 2, (icon.getHeight() - newHeight) / 2, null); graphics.dispose(); return bimage;
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()); }
requestHandlerMap.put(icon.getRelHref(), (session, request, response) -> { response.setContentType(icon.getType()); if (icon.shouldBeCached()) { response.setHeader("Cache-Control", "no-cache, must-revalidate"); icon.write(out);
/** * Return href with '/' -prefix and removed possible ?[fileHash]. * * Used in matching, when serving images. * * @return href with '/' -prefix and removed possible ?[fileHash] */ public String getRelHref() { String[] split = getHref().split("\\?"); return "/" + split[0]; }
private void setRelativeName() { int split = baseName.lastIndexOf('.'); String link = baseName.substring(0, split) + "-" + getSizes() + baseName.substring(split); if (!shouldBeCached) { link = link + "?" + fileHash; } attributes.put("href", link); }
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; }
head.appendChild(icon.asElement());
/** * Gets the cache-string used in Google Workbox caching. * * @return "{ url: '[href]', revision: '[fileHash' }" */ public String getCacheFormat() { return String.format("{ url: '%s', revision: '%s' }", getHref(), fileHash); }