1<?php 2 3use ComboStrap\ColorRgb; 4use ComboStrap\Mime; 5use ComboStrap\Site; 6 7if (!defined('DOKU_INC')) die(); 8 9 10/** 11 * 12 * To add the manifest image 13 * 14 * https://www.dokuwiki.org/devel:manifest 15 * 16 * @see <a href="https://combostrap.com/manifest">manifest</a> 17 * 18 * [[doku>devel:manifest|webmanifest]] 19 * https://developer.mozilla.org/en-US/docs/Web/Manifest 20 */ 21class action_plugin_combo_manifest extends DokuWiki_Action_Plugin 22{ 23 24 25 function register(Doku_Event_Handler $controller) 26 { 27 28 /* This will call the function _manifest */ 29 $controller->register_hook( 30 'MANIFEST_SEND', 31 'AFTER', 32 $this, 33 '_manifest', 34 array() 35 ); 36 37 38 } 39 40 41 /** 42 * Main function; dispatches the visual comment actions 43 * @param $event Doku_Event 44 * 45 * We take into account the file generated by https://realfavicongenerator.net/ 46 * 47 * 48 * 49 */ 50 function _manifest(&$event, $param) 51 { 52 53 $mediaId = ":android-chrome-192x192.png"; 54 $mediaFile = mediaFN($mediaId); 55 if (file_exists($mediaFile)) { 56 $url = ml($mediaId, '', true, '', true); 57 $event->data['icons'][] = 58 array( 59 "src" => $url, 60 "sizes" => "192x192", 61 "type" => "image/png" 62 ); 63 } 64 65 $primaryColor = Site::getPrimaryColor(); 66 if ($primaryColor !== null) { 67 $event->data["theme_color"] = $primaryColor->toRgbHex(); 68 } 69 70 /** 71 * Id setting 72 * https://developer.chrome.com/blog/pwa-manifest-id/ 73 * It seems that this is a unique id domain based 74 * We set then the start_url (ie another pwa may be living on another path) 75 */ 76 $event->data["id"] = $event->data["start_url"]; 77 78 79 /** 80 * Svg must be size any for svg 81 * https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes 82 * otherwise we get this kind of error in devtool. 83 * `` 84 * Actual Size (150x150)px of Icon .... svg does not match the specified size (17x17, 512x512) 85 * `` 86 * Note: 87 * * 150x150 is not the true size 88 * * (17x17, 512x512) is set by dokuwiki 89 */ 90 foreach ($event->data['icons'] as &$iconArray) { 91 if ($iconArray["type"] === Mime::SVG) { 92 $iconArray["sizes"] = "any"; 93 } 94 } 95 96 97 } 98 99 100} 101