From 4869f46ab6fcdc101c4507ad9f40e299e5b649b2 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 7 Aug 2025 15:34:25 -0600 Subject: [PATCH] Fixes (#19420) * Remove torch install * notification fixes the pubkey was not being returned if notifications was not enabled at the global level * Put back * single condition check for fetching and disabling button --------- Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> --- docker/rockchip/Dockerfile | 3 +- frigate/api/notification.py | 7 +- .../settings/NotificationsSettingsView.tsx | 116 ++++++++++-------- 3 files changed, 72 insertions(+), 54 deletions(-) diff --git a/docker/rockchip/Dockerfile b/docker/rockchip/Dockerfile index 5375d19e5..668250439 100644 --- a/docker/rockchip/Dockerfile +++ b/docker/rockchip/Dockerfile @@ -11,8 +11,9 @@ COPY docker/main/requirements-wheels.txt /requirements-wheels.txt COPY docker/rockchip/requirements-wheels-rk.txt /requirements-wheels-rk.txt RUN sed -i "/https:\/\//d" /requirements-wheels.txt RUN sed -i "/onnxruntime/d" /requirements-wheels.txt -RUN pip3 wheel --wheel-dir=/rk-wheels -r /requirements-wheels-rk.txt +RUN pip3 wheel --wheel-dir=/rk-wheels -c /requirements-wheels.txt -r /requirements-wheels-rk.txt RUN rm -rf /rk-wheels/opencv_python-* +RUN rm -rf /rk-wheels/torch-* FROM deps AS rk-frigate ARG TARGETARCH diff --git a/frigate/api/notification.py b/frigate/api/notification.py index 7858ec1a7..96ba96fdc 100644 --- a/frigate/api/notification.py +++ b/frigate/api/notification.py @@ -21,7 +21,12 @@ router = APIRouter(tags=[Tags.notifications]) @router.get("/notifications/pubkey") def get_vapid_pub_key(request: Request): - if not request.app.frigate_config.notifications.enabled: + config = request.app.frigate_config + notifications_enabled = config.notifications.enabled + camera_notifications_enabled = [ + c for c in config.cameras.values() if c.enabled and c.notifications.enabled + ] + if not (notifications_enabled or camera_notifications_enabled): return JSONResponse( content=({"success": False, "message": "Notifications are not enabled."}), status_code=400, diff --git a/web/src/views/settings/NotificationsSettingsView.tsx b/web/src/views/settings/NotificationsSettingsView.tsx index 36213fc0e..82d09107a 100644 --- a/web/src/views/settings/NotificationsSettingsView.tsx +++ b/web/src/views/settings/NotificationsSettingsView.tsx @@ -118,50 +118,6 @@ export default function NotificationView({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [changedValue]); - // notification key handling - - const { data: publicKey } = useSWR( - config?.notifications?.enabled ? "notifications/pubkey" : null, - { revalidateOnFocus: false }, - ); - - const subscribeToNotifications = useCallback( - (registration: ServiceWorkerRegistration) => { - if (registration) { - addMessage( - "notification_settings", - t("notification.unsavedRegistrations"), - undefined, - "registration", - ); - - registration.pushManager - .subscribe({ - userVisibleOnly: true, - applicationServerKey: publicKey, - }) - .then((pushSubscription) => { - axios - .post("notifications/register", { - sub: pushSubscription, - }) - .catch(() => { - toast.error(t("notification.toast.error.registerFailed"), { - position: "top-center", - }); - pushSubscription.unsubscribe(); - registration.unregister(); - setRegistration(null); - }); - toast.success(t("notification.toast.success.registered"), { - position: "top-center", - }); - }); - } - }, - [publicKey, addMessage, t], - ); - // notification state const [registration, setRegistration] = @@ -206,7 +162,69 @@ export default function NotificationView({ }, }); - const watchCameras = form.watch("cameras"); + const watchAllEnabled = form.watch("allEnabled"); + const watchCameras = useMemo(() => form.watch("cameras") || [], [form]); + + const anyCameraNotificationsEnabled = useMemo( + () => + config && + Object.values(config.cameras).some( + (c) => + c.enabled_in_config && + c.notifications && + c.notifications.enabled_in_config, + ), + [config], + ); + + const shouldFetchPubKey = Boolean( + config && + (config.notifications?.enabled || anyCameraNotificationsEnabled) && + (watchAllEnabled || + (Array.isArray(watchCameras) && watchCameras.length > 0)), + ); + + const { data: publicKey } = useSWR( + shouldFetchPubKey ? "notifications/pubkey" : null, + { revalidateOnFocus: false }, + ); + + const subscribeToNotifications = useCallback( + (registration: ServiceWorkerRegistration) => { + if (registration) { + addMessage( + "notification_settings", + t("notification.unsavedRegistrations"), + undefined, + "registration", + ); + + registration.pushManager + .subscribe({ + userVisibleOnly: true, + applicationServerKey: publicKey, + }) + .then((pushSubscription) => { + axios + .post("notifications/register", { + sub: pushSubscription, + }) + .catch(() => { + toast.error(t("notification.toast.error.registerFailed"), { + position: "top-center", + }); + pushSubscription.unsubscribe(); + registration.unregister(); + setRegistration(null); + }); + toast.success(t("notification.toast.success.registered"), { + position: "top-center", + }); + }); + } + }, + [publicKey, addMessage, t], + ); useEffect(() => { if (watchCameras.length > 0) { @@ -521,13 +539,7 @@ export default function NotificationView({