1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-29 09:55:35 +02:00

Merge branch 'main' into custom-messages

This commit is contained in:
Philipp Heckel 2022-03-28 14:14:20 -04:00
commit b20df55b88
6 changed files with 21 additions and 37 deletions

View file

@ -56,6 +56,4 @@ class Poller {
}
const poller = new Poller();
poller.startWorker();
export default poller;

View file

@ -1,7 +1,7 @@
import prefs from "./Prefs";
import subscriptionManager from "./SubscriptionManager";
const delayMillis = 15000; // 15 seconds
const delayMillis = 25000; // 25 seconds
const intervalMillis = 1800000; // 30 minutes
class Pruner {
@ -35,6 +35,4 @@ class Pruner {
}
const pruner = new Pruner();
pruner.startWorker();
export default pruner;

View file

@ -17,18 +17,13 @@ import {BrowserRouter, Outlet, Route, Routes, useOutletContext, useParams} from
import {expandUrl, topicUrl} from "../app/utils";
import ErrorBoundary from "./ErrorBoundary";
import routes from "./routes";
import {useAutoSubscribe, useConnectionListeners, useLocalStorageMigration} from "./hooks";
import {Backdrop, ListItemIcon, ListItemText, Menu} from "@mui/material";
import {useAutoSubscribe, useBackgroundProcesses, useConnectionListeners} from "./hooks";
import {Backdrop} from "@mui/material";
import Paper from "@mui/material/Paper";
import IconButton from "@mui/material/IconButton";
import {MoreVert} from "@mui/icons-material";
import MenuItem from "@mui/material/MenuItem";
import TextField from "@mui/material/TextField";
import SendIcon from "@mui/icons-material/Send";
import priority1 from "../img/priority-1.svg";
import priority2 from "../img/priority-2.svg";
import priority4 from "../img/priority-4.svg";
import priority5 from "../img/priority-5.svg";
import api from "../app/Api";
import SendDialog from "./SendDialog";
@ -80,7 +75,7 @@ const Layout = () => {
});
useConnectionListeners(subscriptions, users);
useLocalStorageMigration();
useBackgroundProcesses();
useEffect(() => updateTitle(newNotificationsCount), [newNotificationsCount]);
return (

View file

@ -6,6 +6,7 @@ import notifier from "../app/Notifier";
import routes from "./routes";
import connectionManager from "../app/ConnectionManager";
import poller from "../app/Poller";
import pruner from "../app/Pruner";
/**
* Wire connectionManager and subscriptionManager so that subscriptions are updated when the connection
@ -67,29 +68,13 @@ export const useAutoSubscribe = (subscriptions, selected) => {
};
/**
* Migrate the 'topics' item in localStorage to the subscriptionManager. This is only done once to migrate away
* from the old web UI.
* Start the poller and the pruner. This is done in a side effect as opposed to just in Pruner.js
* and Poller.js, because side effect imports are not a thing in JS, and "Optimize imports" cleans
* up "unused" imports. See https://github.com/binwiederhier/ntfy/issues/186.
*/
export const useLocalStorageMigration = () => {
const [hasRun, setHasRun] = useState(false);
export const useBackgroundProcesses = () => {
useEffect(() => {
if (hasRun) {
return;
}
const topicsStr = localStorage.getItem("topics");
if (topicsStr) {
const topics = JSON.parse(topicsStr).filter(topic => topic !== "");
if (topics.length > 0) {
(async () => {
for (const topic of topics) {
const baseUrl = window.location.origin;
const subscription = await subscriptionManager.add(baseUrl, topic);
poller.pollInBackground(subscription); // Dangle!
}
localStorage.removeItem("topics");
})();
}
}
setHasRun(true);
poller.startWorker();
pruner.startWorker();
}, []);
}