Skip to content

Commit

Permalink
Add simple WPA + instructions update
Browse files Browse the repository at this point in the history
  • Loading branch information
k0gen committed Jan 24, 2024
1 parent 1e1ee39 commit 8f63770
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
95 changes: 95 additions & 0 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,101 @@ server {
'
echo "$NGINX_CONF" > $CONF_FILE

cd /usr/share/nginx/html
cat <<EOF >service-worker.js
// Define the cache name for versioning
const CACHE_NAME = 'primal-pwa-cache-v1';
// Specify the assets to cache
const ASSETS_TO_CACHE = [
'/',
'/index.html',
'/$(ls assets/index-*.js)',
'/$(ls assets/index-*.css)',
'/$(ls assets/favicon-*.ico)',
'/public/fonts.css',
// Add all other assets like images, fonts from the public directory
'/public/Nacelle/Nacelle-Regular.otf',
'/public/RobotoCondensed/RobotoCondensed-Regular.ttf',
// ... other font files and assets
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => cache.addAll(ASSETS_TO_CACHE))
);
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== CACHE_NAME) {
return caches.delete(cache);
}
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Serve from cache if available, otherwise fetch from network
return response || fetch(event.request);
})
);
});
EOF

cat << EOF >manifest.json
{
"name": "Primal",
"short_name": "Primal",
"icons": [
{
"src": "public/primal-logo-large.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": ".",
"display": "fullscreen",
"orientation": "portrait"
}
EOF

HTML_FILE="/usr/share/nginx/html/index.html"

# Define the line to insert after
INSERT_AFTER='<\/title>'

# Define the manifest code to insert
INSERT_CODE=' <link rel="manifest" href="manifest.json">'

# Use sed to insert the code
sed -i "s|$INSERT_AFTER|$INSERT_AFTER\n$INSERT_CODE|" $HTML_FILE

# Define the worker code to be injected
CODE=' <script>\
if ('"'"'serviceWorker'"'"' in navigator) {\
window.addEventListener('"'"'load'"'"', function() {\
navigator.serviceWorker.register('"'"'service-worker.js'"'"').then(function(registration) {\
console.log('"'"'ServiceWorker registration successful with scope: '"'"', registration.scope);\
}, function(err) {\
console.log('"'"'ServiceWorker registration failed: '"'"', err);\
});\
});\
}\
</script>'

# Use awk to inject the worker code after the specified line
awk -v code="$CODE" '/lottie-player.js"><\/script>/ { print; print code; next }1' $HTML_FILE > temp.html && mv temp.html $HTML_FILE

_term() {
echo "Caught SIGTERM signal!"
kill -SIGTERM "$primal_process" 2>/dev/null
Expand Down
5 changes: 3 additions & 2 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
4. Choose to **Create Account** or if you already have a Nostr account, click **Login**.
5. Follow the onscreen instructions.

Now, you're all set to explore the Nostr world in a sovereign fashion.
Enjoy! 😊
**Note:** While it's possible to use the Primal web app on your mobile device, we currently recommend using the dedicated mobile app for Android and iOS for a better user experience.

Enjoy exploring the Nostr world in a sovereign fashion! 😊

0 comments on commit 8f63770

Please sign in to comment.