forked from mirrors/ntfy
Fix pruning bug in web app (closes #186), release notes, remove local storage migration
This commit is contained in:
parent
d4fe2052c7
commit
182e21a9c3
5 changed files with 12 additions and 29 deletions
|
@ -26,6 +26,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
|
|||
* Spanish (thanks to [@rogeliodh](https://github.com/rogeliodh))
|
||||
* Turkish (thanks to [@ersen](https://ersen.moe/))
|
||||
* Norwegian (thanks to [@comradekingu](https://github.com/comradekingu))
|
||||
* German (thanks to [@cmeis](https://github.com/cmeis))
|
||||
|
||||
**Thanks:**
|
||||
|
||||
|
@ -38,6 +39,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
|
|||
|
||||
* Do not allow comma in topic name in publish via GET endpoint (no ticket)
|
||||
* Add "Access-Control-Allow-Origin: *" for attachments (no ticket, thanks to @FrameXX)
|
||||
* Make pruning run again in web app ([#186](https://github.com/binwiederhier/ntfy/issues/186))
|
||||
|
||||
**Documentation:**
|
||||
|
||||
|
|
|
@ -56,6 +56,4 @@ class Poller {
|
|||
}
|
||||
|
||||
const poller = new Poller();
|
||||
poller.startWorker();
|
||||
|
||||
export default poller;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,7 +17,7 @@ import {BrowserRouter, Outlet, Route, Routes, useOutletContext, useParams} from
|
|||
import {expandUrl} from "../app/utils";
|
||||
import ErrorBoundary from "./ErrorBoundary";
|
||||
import routes from "./routes";
|
||||
import {useAutoSubscribe, useConnectionListeners, useLocalStorageMigration} from "./hooks";
|
||||
import {useAutoSubscribe, useConnectionListeners, useBackgroundProcesses} from "./hooks";
|
||||
|
||||
// TODO add drag and drop
|
||||
// TODO races when two tabs are open
|
||||
|
@ -67,7 +67,7 @@ const Layout = () => {
|
|||
});
|
||||
|
||||
useConnectionListeners(subscriptions, users);
|
||||
useLocalStorageMigration();
|
||||
useBackgroundProcesses();
|
||||
useEffect(() => updateTitle(newNotificationsCount), [newNotificationsCount]);
|
||||
|
||||
return (
|
||||
|
|
|
@ -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();
|
||||
}, []);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue