Skip to content

Commit

Permalink
fix manifest and service worker filestructure/config
Browse files Browse the repository at this point in the history
  • Loading branch information
kibagateaux committed Aug 3, 2024
1 parent ece29a6 commit 964826e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 15 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### App Deployments
Android
[![PWA Status](https://api.netlify.com/api/v1/badges/b8063611-c1d8-4945-b887-788c1294d644/deploy-status)](https://app.netlify.com/sites/jinnihealth/deploys)
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@apollo/client": "^3.8.6",
"@arx-research/libhalo": "^1.2.17",
"@expo/metro-runtime": "~3.2.1",
"@react-native-async-storage/async-storage": "1.23.1",
"@react-native-community/masked-view": "^0.1.11",
"@rneui/base": "^4.0.0-rc.7",
Expand Down Expand Up @@ -50,6 +51,8 @@
"lodash": "^4.17.21",
"process": "^0.11.10",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-helmet-async": "^2.0.5",
"react-native": "0.74.3",
"react-native-calendars": "^1.1301.0",
"react-native-crypto": "^2.2.0",
Expand All @@ -65,6 +68,7 @@
"react-native-screens": "3.31.1",
"react-native-stream": "^0.1.9",
"react-native-svg": "15.2.0",
"react-native-web": "~0.19.10",
"readable-stream": "^1.0.33",
"stream-browserify": "^1.0.0",
"util": "^0.10.4",
Expand All @@ -79,10 +83,7 @@
"workbox-range-requests": "^6.6.0",
"workbox-routing": "^6.6.0",
"workbox-strategies": "^6.6.0",
"workbox-streams": "^6.6.0",
"react-native-web": "~0.19.10",
"react-dom": "18.2.0",
"@expo/metro-runtime": "~3.2.1"
"workbox-streams": "^6.6.0"
},
"peerDependencies": {
"ethers": "5.7.0"
Expand Down
9 changes: 5 additions & 4 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"short_name": "Jinni Health",
"short_name": "Jinni",
"name": "Jinni Health",
"description": "A self-actualiation game based on tamagotchis",
"icons": [
{
"src": "public/favicon.png",
"sizes": "192x192",
"src": "favicon.png",
"sizes": "48x48",
"type": "image/png"
},
{
"src": "public/icon.png",
"src": "icon.png",
"sizes": "512x512",
"type": "image/png"
}
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions src/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// add React Native NodeJS polyfills
import 'utils/polyfills';

/**
* Normal RN imports
*/
import { Platform } from 'react-native';
import React, { useEffect, useState } from 'react';
import { Tabs } from 'expo-router';
import * as Sentry from '@sentry/react-native';
Expand Down Expand Up @@ -49,7 +47,7 @@ const HomeLayout = () => {
);
};

if (window) {
if (Platform.OS === 'web') {
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
Expand Down
8 changes: 7 additions & 1 deletion src/contexts/ExternalServicesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { createContext, useState, useMemo } from 'react';
import { getAppConfig } from 'utils/config';

import { ApolloProvider } from '@apollo/client';
import { Helmet, HelmetProvider } from 'react-helmet-async';
import { getGqlClient } from 'utils/api';
import { SentryClient, SegmentClient, getSegment, getSentry } from 'utils/logging';

Expand Down Expand Up @@ -41,7 +42,12 @@ export const ExternalServicesProvider: React.FC<Props> = ({ children }) => {

return (
<ExternalServicesContext.Provider value={{ sentry, segment }}>
<ApolloProvider client={getGqlClient()}>{children}</ApolloProvider>
<HelmetProvider>
<Helmet>
<link rel="manifest" href="manifest.json"></link>
</Helmet>
<ApolloProvider client={getGqlClient()}>{children}</ApolloProvider>
</HelmetProvider>
</ExternalServicesContext.Provider>
);
};
11 changes: 9 additions & 2 deletions src/utils/serviceWorkerRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const isLocalhost = Boolean(
);

export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
if (
// process.env.NODE_ENV === 'production' &&
'serviceWorker' in navigator
) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
Expand All @@ -30,8 +33,10 @@ export function register(config) {
return;
}

const url = process.env.PUBLIC_URL || `http://${window.location.host}`;
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
const swUrl = `${url}/service-worker.js`;
console.log('service worker url', url, swUrl);

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
Expand Down Expand Up @@ -109,13 +114,15 @@ function checkValidServiceWorker(swUrl, config) {
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
console.log('NO SERVICE WORKER');
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
console.log('SERVICE WORKER REGISTERED');
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
Expand Down

0 comments on commit 964826e

Please sign in to comment.