Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWA: Fix reload, Firefox mp3 load, reduce mobile padding #795

Merged
merged 5 commits into from Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions web/public/sw.js
Expand Up @@ -2,6 +2,7 @@
import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from "workbox-precaching";
import { NavigationRoute, registerRoute } from "workbox-routing";
import { NetworkFirst } from "workbox-strategies";
import { clientsClaim } from "workbox-core";

import { dbAsync } from "../src/app/db";

Expand Down Expand Up @@ -224,6 +225,8 @@ precacheAndRoute(
self.__WB_MANIFEST
);

// Claim all open windows
clientsClaim();
// Delete any cached old dist files from previous service worker versions
cleanupOutdatedCaches();

Expand Down
5 changes: 2 additions & 3 deletions web/src/components/App.jsx
@@ -1,25 +1,24 @@
import * as React from "react";
import { createContext, Suspense, useContext, useEffect, useState, useMemo } from "react";
import { Box, Toolbar, CssBaseline, Backdrop, CircularProgress, useMediaQuery } from "@mui/material";
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { Box, Toolbar, CssBaseline, Backdrop, CircularProgress, useMediaQuery, ThemeProvider, createTheme } from "@mui/material";
import { useLiveQuery } from "dexie-react-hooks";
import { BrowserRouter, Outlet, Route, Routes, useParams } from "react-router-dom";
import { AllSubscriptions, SingleSubscription } from "./Notifications";
import { darkTheme, lightTheme } from "./theme";
import Navigation from "./Navigation";

Check warning on line 8 in web/src/components/App.jsx

View workflow job for this annotation

GitHub Actions / test

Dependency cycle detected
import ActionBar from "./ActionBar";

Check warning on line 9 in web/src/components/App.jsx

View workflow job for this annotation

GitHub Actions / test

Dependency cycle via ./SubscriptionPopup:21
import Preferences from "./Preferences";

Check warning on line 10 in web/src/components/App.jsx

View workflow job for this annotation

GitHub Actions / test

Dependency cycle detected
import subscriptionManager from "../app/SubscriptionManager";
import userManager from "../app/UserManager";
import { expandUrl } from "../app/utils";
import ErrorBoundary from "./ErrorBoundary";
import routes from "./routes";
import { useAccountListener, useBackgroundProcesses, useConnectionListeners, useWebPushTopics } from "./hooks";
import PublishDialog from "./PublishDialog";

Check warning on line 17 in web/src/components/App.jsx

View workflow job for this annotation

GitHub Actions / test

Dependency cycle detected
import Messaging from "./Messaging";
import Login from "./Login";
import Signup from "./Signup";
import Account from "./Account";

Check warning on line 21 in web/src/components/App.jsx

View workflow job for this annotation

GitHub Actions / test

Dependency cycle detected
import "../app/i18n"; // Translations!
import prefs, { THEME } from "../app/Prefs";

Expand Down Expand Up @@ -133,7 +132,7 @@
display: "flex",
flexGrow: 1,
flexDirection: "column",
padding: 3,
padding: { xs: 0, md: 3 },
width: { sm: `calc(100% - ${Navigation.width}px)` },
height: "100dvh",
overflow: "auto",
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Notifications.jsx
Expand Up @@ -184,7 +184,7 @@ const NotificationItem = (props) => {
const hasUserActions = notification.actions && notification.actions.length > 0;
const showActions = hasAttachmentActions || hasClickAction || hasUserActions;
return (
<Card sx={{ minWidth: 275, padding: 1 }} role="listitem" aria-label={t("notifications_list_item")}>
<Card sx={{ padding: 1 }} role="listitem" aria-label={t("notifications_list_item")}>
<CardContent>
<Tooltip title={t("notifications_delete")} enterDelay={500}>
<IconButton onClick={handleDelete} sx={{ float: "right", marginRight: -1, marginTop: -1 }} aria-label={t("notifications_delete")}>
Expand Down
7 changes: 7 additions & 0 deletions web/src/components/theme.js
Expand Up @@ -55,6 +55,13 @@ export const darkTheme = {
},
},
},
MuiPaper: {
styleOverrides: {
root: {
backgroundImage: "none",
},
},
},
},
binwiederhier marked this conversation as resolved.
Show resolved Hide resolved
palette: {
mode: "dark",
Expand Down
28 changes: 28 additions & 0 deletions web/src/index.jsx
@@ -1,6 +1,34 @@
import * as React from "react";
import { createRoot } from "react-dom/client";
// eslint-disable-next-line import/no-unresolved
import { registerSW } from "virtual:pwa-register";
import App from "./components/App";

// fetch new sw every hour, i.e. update app every hour while running
const intervalMS = 60 * 60 * 1000;

// https://vite-pwa-org.netlify.app/guide/periodic-sw-updates.html
registerSW({
onRegisteredSW(swUrl, registration) {
if (!registration) {
return;
}

setInterval(async () => {
if (registration.installing || navigator?.onLine === false) return;

const resp = await fetch(swUrl, {
cache: "no-store",
headers: {
cache: "no-store",
"cache-control": "no-cache",
},
});

if (resp?.status === 200) await registration.update();
}, intervalMS);
},
});

nimbleghost marked this conversation as resolved.
Show resolved Hide resolved
const root = createRoot(document.querySelector("#root"));
root.render(<App />);
4 changes: 2 additions & 2 deletions web/vite.config.js
Expand Up @@ -16,7 +16,7 @@ export default defineConfig(({ mode }) => ({
react(),
VitePWA({
registerType: "autoUpdate",
injectRegister: "inline",
injectRegister: null,
nimbleghost marked this conversation as resolved.
Show resolved Hide resolved
strategies: "injectManifest",
devOptions: {
enabled: true,
Expand All @@ -25,7 +25,7 @@ export default defineConfig(({ mode }) => ({
navigateFallback: "index.html",
},
injectManifest: {
globPatterns: ["**/*.{js,css,html,mp3,ico,png,svg,json}"],
globPatterns: ["**/*.{js,css,html,ico,png,svg,json}"],
globIgnores: ["config.js"],
manifestTransforms: [
(entries) => ({
Expand Down