mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									5e5beb9837
								
							
						
					
					
						commit
						4869f46ab6
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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({
 | 
			
		||||
                  </Heading>
 | 
			
		||||
                  <Button
 | 
			
		||||
                    aria-label={t("notification.registerDevice")}
 | 
			
		||||
                    disabled={
 | 
			
		||||
                      (!config?.notifications.enabled &&
 | 
			
		||||
                        notificationCameras.length === 0 &&
 | 
			
		||||
                        !form.watch("allEnabled") &&
 | 
			
		||||
                        form.watch("cameras").length === 0) ||
 | 
			
		||||
                      publicKey == undefined
 | 
			
		||||
                    }
 | 
			
		||||
                    disabled={!shouldFetchPubKey || publicKey == undefined}
 | 
			
		||||
                    onClick={() => {
 | 
			
		||||
                      if (registration == null) {
 | 
			
		||||
                        Notification.requestPermission().then((permission) => {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user