From 182e21a9c367d17c85a288c925ebbaefca4aed92 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sun, 27 Mar 2022 09:20:25 -0400 Subject: [PATCH 1/3] Fix pruning bug in web app (closes #186), release notes, remove local storage migration --- docs/releases.md | 2 ++ web/src/app/Poller.js | 2 -- web/src/app/Pruner.js | 4 +--- web/src/components/App.js | 4 ++-- web/src/components/hooks.js | 29 +++++++---------------------- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/docs/releases.md b/docs/releases.md index 5b6f2594..7105f442 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -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:** diff --git a/web/src/app/Poller.js b/web/src/app/Poller.js index 9de417a5..ec284eaf 100644 --- a/web/src/app/Poller.js +++ b/web/src/app/Poller.js @@ -56,6 +56,4 @@ class Poller { } const poller = new Poller(); -poller.startWorker(); - export default poller; diff --git a/web/src/app/Pruner.js b/web/src/app/Pruner.js index 9fac28e0..45948057 100644 --- a/web/src/app/Pruner.js +++ b/web/src/app/Pruner.js @@ -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; diff --git a/web/src/components/App.js b/web/src/components/App.js index 4782a26c..5be7ec9f 100644 --- a/web/src/components/App.js +++ b/web/src/components/App.js @@ -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 ( diff --git a/web/src/components/hooks.js b/web/src/components/hooks.js index bc88cef8..3714a9d0 100644 --- a/web/src/components/hooks.js +++ b/web/src/components/hooks.js @@ -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(); }, []); } From dc1c0ddd4e9618ab6f6bc4b58cbdaa84e93b1409 Mon Sep 17 00:00:00 2001 From: "Philipp C. Heckel" Date: Mon, 28 Mar 2022 11:07:05 -0400 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 78b9f324..94ac1d4f 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ the [build instructions](https://ntfy.sh/docs/develop/) for the server and the A Or, if you'd like to help translate πŸ‡©πŸ‡ͺ πŸ‡ΊπŸ‡Έ πŸ‡§πŸ‡¬, you can start immediately in [Hosted Weblate](https://hosted.weblate.org/projects/ntfy/). + +Translation status + + ## Contact me You can directly contact me **[on Discord](https://discord.gg/cT7ECsZj9w)** or [on Matrix](https://matrix.to/#/#ntfy:matrix.org) (bridged from Discord), or via the [GitHub issues](https://github.com/binwiederhier/ntfy/issues), or find more contact information From 3b4a4108e54f9e989a58b7f1cbed3906e628443f Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Mon, 28 Mar 2022 14:10:14 -0400 Subject: [PATCH 3/3] Release log --- docs/releases.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/releases.md b/docs/releases.md index 7105f442..fe1f5f31 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -11,8 +11,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release * Download attachments to cache folder ([#181](https://github.com/binwiederhier/ntfy/issues/181)) * Regularly delete attachments for deleted notifications ([#142](https://github.com/binwiederhier/ntfy/issues/142)) * Translations to different languages ([#188](https://github.com/binwiederhier/ntfy/issues/188), thanks to - [@StoyanDimitrov](https://github.com/StoyanDimitrov) for initiating things, and thanks to [@comradekingu](https://github.com/comradekingu) - for refining some English language strings) + [@StoyanDimitrov](https://github.com/StoyanDimitrov) for initiating things) **Bugs:** @@ -22,11 +21,14 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release **Translations:** +* English language improvements (thanks to [@comradekingu](https://github.com/comradekingu)) * Bulgarian (thanks to [@StoyanDimitrov](https://github.com/StoyanDimitrov)) * 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)) +* Chinese (thanks to [@poi](https://hosted.weblate.org/user/poi)) +* Dutch (thanks to [@diony](https://hosted.weblate.org/user/diony)) **Thanks:**