'use strict'; const PREFERRED_ICON_SIZE = 60; const GAIA_CORE_APP_SRCDIR = 'apps'; const GAIA_EXTERNAL_APP_SRCDIR = 'external-apps'; const INSTALL_TIME = 132333986000; // Match this to value in webapp-manifests.js // Initial Homescreen icon descriptors. // c.f. the corresponding implementation in the Homescreen app. function bestMatchingIcon(preferred_size, manifest, origin) { var icons = manifest.icons; if (!icons) { return undefined; } var preferredSize = Number.MAX_VALUE; var max = 0; for (var size in icons) { size = parseInt(size, 10); if (size > max) max = size; if (size >= PREFERRED_ICON_SIZE && size < preferredSize) preferredSize = size; } // If there is an icon matching the preferred size, we return the result, // if there isn't, we will return the maximum available size. if (preferredSize === Number.MAX_VALUE) preferredSize = max; var url = icons[preferredSize]; if (!url) { return undefined; } // If the icon path is not an absolute URL, prepend the app's origin. if (url.indexOf('data:') == 0 || url.indexOf('app://') == 0 || url.indexOf('http://') == 0 || url.indexOf('https://') == 0) return url; return origin + url; } function iconDescriptor(directory, app_name, entry_point) { let origin = gaiaOriginURL(app_name); let manifestURL = gaiaManifestURL(app_name); // For external/3rd party apps that don't use the Gaia domain, we have an // 'origin' file that specifies the URL. let dir = getFile(GAIA_DIR, directory, app_name); let originFile = dir.clone(); originFile.append("origin"); if (originFile.exists()) { origin = getFileContent(originFile).replace(/^\s+|\s+$/, ''); if (origin.slice(-1) == "/") { manifestURL = origin + "manifest.webapp"; } else { manifestURL = origin + "/manifest.webapp"; } } let manifestFile = dir.clone(); manifestFile.append("manifest.webapp"); let manifest = getJSON(manifestFile); if (entry_point && manifest.entry_points && manifest.entry_points[entry_point]) { manifest = manifest.entry_points[entry_point]; } let icon = bestMatchingIcon(PREFERRED_ICON_SIZE, manifest, origin); //TODO set localizedName once we know the default locale return { manifestURL: manifestURL, entry_point: entry_point, updateTime: INSTALL_TIME, name: manifest.name, icon: icon }; }