Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
www/mobile: Add suport for Android Chrome app install banners
Browse files Browse the repository at this point in the history
  • Loading branch information
bakape committed Apr 27, 2016
1 parent d37f696 commit 62cd138
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
29 changes: 1 addition & 28 deletions client/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,9 @@
* Various mobile-only code
*/

let main = require('./main'),
{$} = main;
let main = require('./main')

// TODO: Remove this module and related server-side logic/assets, once we
// build a separate mobile bundle

main.defer(function() {
// User refused the first time
if (!main.isMobile || localStorage.homescreenRefused)
return;
// Only comatible with Android Chrome for now
const n = navigator.userAgent,
isChrome = /Chrome/.test(n),
isFF = /Firefox/.test(n);
// Only Chrome works for now
let msg ='To install meguca as a fullscreen webapp, tap the menu button'
+ ' and select ';
if (isChrome)
msg += '"Add to home screen"';
else if (isFF)
msg += '"Page > Add to Home Screen"';
msg += '. Tap this message to close. It will not appear again.';

$('<a class="mobile">Install Webapp</a>')
.click(function(e){
main.request('notification', msg);
e.target.remove();
localStorage.homescreenRefused = true;
})
.appendTo('#banner_center');
});

main.oneeSama.hook('spoilerTag', main.etc.touchable_spoiler_tag);
6 changes: 6 additions & 0 deletions www/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ Selects and loads the client files
}
});
});

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("../worker.js").catch(function (err) {
throw err
})
}
})();
7 changes: 5 additions & 2 deletions www/mobile/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Meguca.org",
"name": "meguca.org",
"short_name": "meguca.org",
"icons": [
{
"src": "/mobile/icon48.png",
Expand Down Expand Up @@ -29,5 +30,7 @@
],
"start_url": "/",
"display": "fullscreen",
"orientation": "any"
"orientation": "any",
"theme_color": "#1d1f21",
"background_color": "#1d1f21"
}
8 changes: 8 additions & 0 deletions www/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Pointless service worker, so we can get Android Chrome native app install
// prompts.

self.addEventListener('install', function () {})

self.addEventListener('activate', function () {})

self.addEventListener('fetch', function () {})

0 comments on commit 62cd138

Please sign in to comment.