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()); }
private String manifestCache() { return String.format(WORKBOX_CACHE_FORMAT, pwaConfiguration.getManifestPath(), manifestJson.hashCode()); }
/** * Google Workbox cache resource String of offline page. example: * {@code {url: 'offline.html', revision: '1234567'}} * * @return Google Workbox cache resource String of offline page */ public String offlinePageCache() { return String.format(WORKBOX_CACHE_FORMAT, pwaConfiguration.getOfflinePath(), offlineHash); }
JsonObject manifestData = Json.createObject(); manifestData.put("name", pwaConfiguration.getAppName()); manifestData.put("short_name", pwaConfiguration.getShortName()); if (!pwaConfiguration.getDescription().isEmpty()) { manifestData.put("description", pwaConfiguration.getDescription()); manifestData.put("display", pwaConfiguration.getDisplay()); manifestData.put("background_color", pwaConfiguration.getBackgroundColor()); manifestData.put("theme_color", pwaConfiguration.getThemeColor()); manifestData.put("start_url", pwaConfiguration.getStartUrl()); manifestData.put("scope", pwaConfiguration.getRootUrl());
if (config.isEnabled()) { .attr(CONTENT_ATTRIBUTE, config.getThemeColor()); head.appendElement(META_TAG) .attr("name", "apple-mobile-web-app-status-bar-style") .attr(CONTENT_ATTRIBUTE, config.getThemeColor()); config.getManifestPath()); + " window.addEventListener('load', function() {\n" + " navigator.serviceWorker.register('" + config.getServiceWorkerPath() + "');\n" + " });\n" + "}"); if (registry.getPwaConfiguration().isInstallPromptEnabled()) {
pwaConfiguration = new PwaConfiguration(pwa, servletContext); if (pwaConfiguration.isEnabled()) { URL logo = servletContext .getResource(pwaConfiguration.relIconPath()); URL offlinePage = servletContext .getResource(pwaConfiguration.relOfflinePath());
return offlinePage.replace("%%%PROJECT_NAME%%%", config.getAppName()) .replace("%%%BACKGROUND_COLOR%%%", config.getBackgroundColor()) .replace("%%%LOGO_PATH%%%", largest != null ? pwaConfiguration.getRootUrl() + largest.getHref() : "")
for (String resource : pwaConfiguration.getOfflineResources()) { filesToCahe.add(String.format(WORKBOX_CACHE_FORMAT, resource.replaceAll("'", ""), servletContext.hashCode())); .append(" .catch(function() {\n") .append(String.format(" return caches.match('%s');%n", getPwaConfiguration().getOfflinePath())) .append(" })\n );\n }\n });");
protected PwaConfiguration(PWA pwa, ServletContext servletContext) { rootUrl = hasContextPath(servletContext) ? servletContext.getContextPath() + "/" : "/"; backgroundColor = pwa.backgroundColor(); themeColor = pwa.themeColor(); iconPath = checkPath(pwa.iconPath()); manifestPath = checkPath(pwa.manifestPath()); offlinePath = checkPath(pwa.offlinePath()); display = pwa.display(); startPath = pwa.startPath().replaceAll("^/+", "");
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; }