(null);
+
+ useEffect(() => {
+ if (!state) return;
+
+ const eventTs = (state as any)?.ts ?? null;
+ const isDefault = !!(state as any)?.data?.is_default_state;
+
+ // skip the default snapshot emitted on connect
+ if (isDefault) return;
+
+ // dedupe identical events
+ if (eventTs != null && lastToastTs.current === eventTs) return;
+ lastToastTs.current = eventTs;
+
+ try {
+ const data = (state as any).data;
+ const title = (state as any)?.name ?? "Laser State";
+ const ls = data?.laser_state;
+ const parts: string[] = [];
+ if (ls) {
+ if (typeof ls.target_diameter === "number") parts.push(`target ${ls.target_diameter.toFixed(2)} mm`);
+ if (typeof ls.higher_tolerance === "number") parts.push(`+${ls.higher_tolerance.toFixed(2)} mm`);
+ if (typeof ls.lower_tolerance === "number") parts.push(`-${ls.lower_tolerance.toFixed(2)} mm`);
+ }
+
+ const message = parts.length > 0 ? parts.join(" · ") : undefined;
+
+ // Sonner toast call — adjust options if you want persistent/critical styling
+ toast(
+
+ ${title}
+ ${message ? ` — ${message}` : ""}
+
+
,
+ {
+ duration: Infinity,
+ position: "top-center",
+ style: { background: "transparent", padding: 0, boxShadow: "none", border: "none" },
+ }
+ );
+ } catch (err) {
+ console.error("GlobalLaserToastManager: failed to build toast", err);
+ toast("Laser state changed");
+ }
+ }, [state]);
+
+ return null;
+}
diff --git a/package-lock.json b/package-lock.json
deleted file mode 100644
index b8f91335..00000000
--- a/package-lock.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "name": "control",
- "lockfileVersion": 3,
- "requires": true,
- "packages": {}
-}
From 0dba0f2774526c7ddd7d6943c5edf44612e494d1 Mon Sep 17 00:00:00 2001
From: snacj <0xsnacj@proton.me>
Date: Fri, 17 Oct 2025 16:54:29 +0200
Subject: [PATCH 8/8] Removed package-lock from root folder
---
.../src/setup/GlobalLaserToastManager.tsx | 140 ------------------
1 file changed, 140 deletions(-)
delete mode 100644 electron/src/setup/GlobalLaserToastManager.tsx
diff --git a/electron/src/setup/GlobalLaserToastManager.tsx b/electron/src/setup/GlobalLaserToastManager.tsx
deleted file mode 100644
index bbace23b..00000000
--- a/electron/src/setup/GlobalLaserToastManager.tsx
+++ /dev/null
@@ -1,140 +0,0 @@
-import React, { useEffect, useRef, useState } from "react";
-import { toast } from "sonner";
-import { useMainNamespace } from "@/client/mainNamespace";
-import { useLaser1Namespace } from "@/machines/laser/laser1/laser1Namespace";
-import { laser1 } from "@/machines/properties";
-import type { MachineIdentificationUnique } from "@/machines/types";
-
-/**
- * Global manager that toasts laser StateEvent changes (non-default) for a single laser.
- * If machineIdentification is omitted it will attempt to discover the laser via the main namespace.
- *
- * Mount once in App.tsx so it persists across routes.
- */
-export function GlobalLaserToastManager({
- machineIdentification,
-}: {
- machineIdentification?: MachineIdentificationUnique;
-}) {
- const main = useMainNamespace();
- const [discovered, setDiscovered] = useState(null);
-
- // Prefer explicit prop, otherwise use discovered id
- const effectiveId = machineIdentification ?? discovered;
-
- // Attempt to discover the single laser machine from the main namespace
- useEffect(() => {
- if (machineIdentification) return;
- const machinesEvent = (main as any)?.machines;
- if (!machinesEvent) {
- setDiscovered(null);
- return;
- }
-
- // Defensive shapes: try common structures
- let list: any[] = [];
- if (Array.isArray(machinesEvent?.data?.machines)) list = machinesEvent.data.machines;
- else if (Array.isArray(machinesEvent?.data)) list = machinesEvent.data;
- else if (Array.isArray(machinesEvent?.machines)) list = machinesEvent.machines;
- else if (machinesEvent && typeof machinesEvent === "object") {
- list = Object.values(machinesEvent).filter((v) => v && typeof v === "object");
- }
-
- const match = list.find((entry) => {
- const mi =
- entry?.machine_identification ||
- entry?.machine_identification_unique?.machine_identification ||
- entry?.device_machine_identification?.machine_identification;
- if (!mi) return false;
- return (
- mi.vendor === (laser1.machine_identification as any).vendor &&
- mi.machine === (laser1.machine_identification as any).machine
- );
- });
-
- if (match) {
- const serial =
- match?.serial ??
- match?.machine_identification_unique?.serial ??
- match?.device_machine_identification?.machine_identification_unique?.serial ??
- null;
- if (serial != null && !Number.isNaN(Number(serial))) {
- setDiscovered({
- machine_identification: laser1.machine_identification,
- serial: Number(serial),
- });
- return;
- }
- }
-
- setDiscovered(null);
- }, [main, machineIdentification]);
-
- return effectiveId ? : null;
-}
-
-/**
- * Watches StateEvent for the laser namespace and shows toasts for non-default states.
- * Component is non-visual.
- */
-function LaserToastWatcher({ machineIdentification }: { machineIdentification: MachineIdentificationUnique }) {
- const { state } = useLaser1Namespace(machineIdentification);
-
- // Deduplicate toasts by event timestamp
- const lastToastTs = useRef(null);
-
- useEffect(() => {
- if (!state) return;
-
- const eventTs = (state as any)?.ts ?? null;
- const isDefault = !!(state as any)?.data?.is_default_state;
-
- // skip the default snapshot emitted on connect
- if (isDefault) return;
-
- // dedupe identical events
- if (eventTs != null && lastToastTs.current === eventTs) return;
- lastToastTs.current = eventTs;
-
- try {
- const data = (state as any).data;
- const title = (state as any)?.name ?? "Laser State";
- const ls = data?.laser_state;
- const parts: string[] = [];
- if (ls) {
- if (typeof ls.target_diameter === "number") parts.push(`target ${ls.target_diameter.toFixed(2)} mm`);
- if (typeof ls.higher_tolerance === "number") parts.push(`+${ls.higher_tolerance.toFixed(2)} mm`);
- if (typeof ls.lower_tolerance === "number") parts.push(`-${ls.lower_tolerance.toFixed(2)} mm`);
- }
-
- const message = parts.length > 0 ? parts.join(" · ") : undefined;
-
- // Sonner toast call — adjust options if you want persistent/critical styling
- toast(
-
- ${title}
- ${message ? ` — ${message}` : ""}
-
-
,
- {
- duration: Infinity,
- position: "top-center",
- style: { background: "transparent", padding: 0, boxShadow: "none", border: "none" },
- }
- );
- } catch (err) {
- console.error("GlobalLaserToastManager: failed to build toast", err);
- toast("Laser state changed");
- }
- }, [state]);
-
- return null;
-}