Skip to content

Commit

Permalink
Chrome install app banner
Browse files Browse the repository at this point in the history
(Works on SSL sites only)
  • Loading branch information
benwerd committed Mar 12, 2015
1 parent bd8c58f commit 5138b4c
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Idno/Core/Idno.php
Expand Up @@ -149,6 +149,9 @@ function registerpages()
$this->addPageHandler('/share/?', '\Idno\Pages\Entity\Share');
$this->addPageHandler('/bookmarklet\.js', '\Idno\Pages\Entity\Bookmarklet', true);

/** Mobile integrations */
$this->addPageHandler('/chrome/manifest\.json', '\Idno\Pages\Chrome\Manifest', true);

/** Files */
$this->addPageHandler('/file/upload/?', '\Idno\Pages\File\Upload', true);
$this->addPageHandler('/file/picker/?', '\Idno\Pages\File\Picker', true);
Expand Down
17 changes: 17 additions & 0 deletions Idno/Pages/Chrome/Manifest.php
@@ -0,0 +1,17 @@
<?php

namespace Idno\Pages\Chrome {

use Idno\Common\Page;

class Manifest extends Page {

function getContent() {

echo \Idno\Core\site()->template()->draw('chrome/manifest');

}

}

}
3 changes: 3 additions & 0 deletions chrome/service-worker.js
@@ -0,0 +1,3 @@
/*
Nothing to see here ...
*/
Binary file added gfx/logos/logo_k_144.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/logos/logo_k_192.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/logos/logo_k_36.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/logos/logo_k_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/logos/logo_k_72.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/logos/logo_k_96.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions templates/default/chrome/manifest.tpl.php
@@ -0,0 +1,43 @@
<?php

header("Content-type: application/json");

?>
{
"name": "<?=htmlspecialchars(\Idno\Core\site()->config()->getTitle())?>",
"short_name": "<?=htmlspecialchars(\Idno\Core\site()->config()->getTitle())?>",
"icons": [
{
"src": "<?=\Idno\Core\site()->config()->getDisplayURL()?>gfx/logos/logo_k_36.png",
"sizes": "36x36",
"type": "image/png"
},
{
"src": "<?=\Idno\Core\site()->config()->getDisplayURL()?>gfx/logos/logo_k_48.png",
"sizes": "48x48",
"type": "image/png"
},
{
"src": "<?=\Idno\Core\site()->config()->getDisplayURL()?>gfx/logos/logo_k_72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "<?=\Idno\Core\site()->config()->getDisplayURL()?>gfx/logos/logo_k_96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "<?=\Idno\Core\site()->config()->getDisplayURL()?>gfx/logos/logo_k_144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "<?=\Idno\Core\site()->config()->getDisplayURL()?>gfx/logos/logo_k_192.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "../",
"display": "standalone"
}
21 changes: 21 additions & 0 deletions templates/default/shell.tpl.php
Expand Up @@ -25,6 +25,27 @@
<?= $this->draw('shell/favicon'); ?>

<?php

if (\Idno\Core\site()->session()->isLoggedIn()) {

?>
<link rel="manifest" href="<?=\Idno\Core\site()->config()->getDisplayURL()?>chrome/manifest.json">
<script>
window.addEventListener('load', function() {
navigator.serviceWorker.register('<?=\Idno\Core\site()->config()->getDisplayURL()?>chrome/service-worker.js', { scope: '/' })
.then(function(r) {
console.log('Registered service worker');
})
.catch(function(whut) {
console.error('Could not register service worker');
console.error(whut);

This comment has been minimized.

Copy link
@benwerd

benwerd Mar 12, 2015

Author Member

Which where? Maybe?

This comment has been minimized.

Copy link
@mapkyca

mapkyca Mar 12, 2015

Member

Don't worry, my late evening mistake :)

});
});
</script>
<?php

}

$opengraph = array(
'og:type' => 'website',
'og:title' => htmlspecialchars(strip_tags($vars['title'])),
Expand Down

0 comments on commit 5138b4c

Please sign in to comment.