[130] Eine Fenster-Brücke statt vier Kopien (useWindowBridgeHost)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
6 files changed
+72
-179
No files matched your search
@@ -1156,6 +1156,9 @@ Prüfung des ganzen Programms (Rust-Kern, TS-Hülle, Build/Sicherheit), nur Code
|
||||
relative Importe (Ausnahmelisten leer). · S
|
||||
- ◐ **[130] Kleinkram:** eine generische Fenster-Brücke statt 5 Kopien; Auswahl als ein `Selection`-Objekt statt
|
||||
12 Felder; `primitives.tsx` auf Overlay zurückschneiden; Cargo-Workspace. · M
|
||||
4.11.: generische Fenster-Brücke `native/windowBridge.ts` (`useWindowBridgeHost`) für Einstellungen, Geschosse,
|
||||
Ebenen-Einstellungen und Kontext-Import (−110 Zeilen); Ressourcen-Fenster bleibt eigen (Teil-Änderungen, [121]).
|
||||
Nicht in der Tauri-App geprüft.
|
||||
3.11. Lizenzteil erledigt: NOTICE ergänzt (OFL-Schriften, wgpu, Tauri, React, pdf.js, jsPDF, lcms, truck …),
|
||||
`src-tauri/deny.toml` + CI-Job `licenses` (check.yml, `cargo deny check licenses` je Crate).
|
||||
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { isTauriRuntime } from "./projectFile";
|
||||
import type { GeoAnchor } from "../ui/ContextImportDialog";
|
||||
import { BORDERLESS_WINDOW_CHROME } from "./windowChrome";
|
||||
import { useWindowBridgeHost, type WindowHandlers } from "./windowBridge";
|
||||
|
||||
const CONTEXT_IMPORT_WINDOW_LABEL = "context-import";
|
||||
|
||||
@@ -55,45 +54,5 @@ export function useContextImportWindowHost(
|
||||
geoAnchor: GeoAnchor | undefined,
|
||||
handlers: ContextImportCommandHandlers,
|
||||
): void {
|
||||
const handlersRef = useRef(handlers);
|
||||
handlersRef.current = handlers;
|
||||
const geoAnchorRef = useRef(geoAnchor);
|
||||
geoAnchorRef.current = geoAnchor;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
let disposed = false;
|
||||
const unlisten: Array<() => void> = [];
|
||||
void (async () => {
|
||||
const { listen, emitTo } = await import("@tauri-apps/api/event");
|
||||
if (disposed) return;
|
||||
unlisten.push(
|
||||
await listen<{ name: string; args: unknown[] }>("context-import-command", (e) => {
|
||||
const fn = (handlersRef.current as unknown as Record<string, unknown>)[e.payload.name];
|
||||
if (typeof fn === "function") (fn as (...a: unknown[]) => void)(...e.payload.args);
|
||||
}),
|
||||
);
|
||||
unlisten.push(
|
||||
await listen("context-import-window-ready", () => {
|
||||
void emitTo(CONTEXT_IMPORT_WINDOW_LABEL, "context-import-sync-state", {
|
||||
geoAnchor: geoAnchorRef.current,
|
||||
}).catch(() => {});
|
||||
}),
|
||||
);
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
unlisten.forEach((u) => u());
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
void (async () => {
|
||||
const { emitTo } = await import("@tauri-apps/api/event");
|
||||
await emitTo(CONTEXT_IMPORT_WINDOW_LABEL, "context-import-sync-state", {
|
||||
geoAnchor,
|
||||
}).catch(() => {});
|
||||
})();
|
||||
}, [geoAnchor]);
|
||||
useWindowBridgeHost(CONTEXT_IMPORT_WINDOW_LABEL, "context-import", { geoAnchor }, handlers as unknown as WindowHandlers, [geoAnchor]);
|
||||
}
|
||||
@@ -17,11 +17,10 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { isTauriRuntime } from "./projectFile";
|
||||
import type { DrawingLevel } from "../model/types";
|
||||
import type { DisplayMode } from "../panels/types";
|
||||
import { BORDERLESS_WINDOW_CHROME } from "./windowChrome";
|
||||
import { useWindowBridgeHost, type WindowHandlers } from "./windowBridge";
|
||||
|
||||
const DRAWING_LEVELS_WINDOW_LABEL = "drawing-levels";
|
||||
|
||||
@@ -65,47 +64,5 @@ export function useDrawingLevelsWindowHost(
|
||||
state: DrawingLevelsSyncState,
|
||||
handlers: DrawingLevelsCommandHandlers,
|
||||
): void {
|
||||
const handlersRef = useRef(handlers);
|
||||
handlersRef.current = handlers;
|
||||
const stateRef = useRef(state);
|
||||
stateRef.current = state;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
let disposed = false;
|
||||
const unlisten: Array<() => void> = [];
|
||||
void (async () => {
|
||||
const { listen, emitTo } = await import("@tauri-apps/api/event");
|
||||
if (disposed) return;
|
||||
unlisten.push(
|
||||
await listen<{ name: string; args: unknown[] }>("drawing-levels-command", (e) => {
|
||||
const fn = (handlersRef.current as unknown as Record<string, unknown>)[e.payload.name];
|
||||
if (typeof fn === "function") (fn as (...a: unknown[]) => void)(...e.payload.args);
|
||||
}),
|
||||
);
|
||||
unlisten.push(
|
||||
await listen("drawing-levels-window-ready", () => {
|
||||
void emitTo(
|
||||
DRAWING_LEVELS_WINDOW_LABEL,
|
||||
"drawing-levels-sync-state",
|
||||
stateRef.current,
|
||||
).catch(() => {});
|
||||
}),
|
||||
);
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
unlisten.forEach((u) => u());
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
void (async () => {
|
||||
const { emitTo } = await import("@tauri-apps/api/event");
|
||||
await emitTo(DRAWING_LEVELS_WINDOW_LABEL, "drawing-levels-sync-state", state).catch(
|
||||
() => {},
|
||||
);
|
||||
})();
|
||||
}, [state]);
|
||||
useWindowBridgeHost(DRAWING_LEVELS_WINDOW_LABEL, "drawing-levels", state, handlers as unknown as WindowHandlers);
|
||||
}
|
||||
@@ -21,11 +21,10 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { isTauriRuntime } from "./projectFile";
|
||||
import { findCategory } from "../model/layers";
|
||||
import type { HatchStyle, LayerCategory, Project } from "../model/types";
|
||||
import { BORDERLESS_WINDOW_CHROME } from "./windowChrome";
|
||||
import { useWindowBridgeHost } from "./windowBridge";
|
||||
|
||||
const LAYER_SETTINGS_WINDOW_LABEL = "layer-settings";
|
||||
|
||||
@@ -83,52 +82,6 @@ export function useLayerSettingsWindowHost(
|
||||
code: string | null,
|
||||
onPatchCategory: (code: string, patch: Partial<LayerCategory>) => void,
|
||||
): void {
|
||||
const stateRef = useRef<LayerSettingsSyncState | null>(code ? stateFor(project, code) : null);
|
||||
stateRef.current = code ? stateFor(project, code) : null;
|
||||
const onPatchRef = useRef(onPatchCategory);
|
||||
onPatchRef.current = onPatchCategory;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
let disposed = false;
|
||||
const unlisten: Array<() => void> = [];
|
||||
void (async () => {
|
||||
const { listen, emitTo } = await import("@tauri-apps/api/event");
|
||||
if (disposed) return;
|
||||
unlisten.push(
|
||||
await listen<{ name: string; args: unknown[] }>("layer-settings-command", (e) => {
|
||||
if (e.payload.name === "onPatchCategory") {
|
||||
const [c, patch] = e.payload.args as [string, Partial<LayerCategory>];
|
||||
onPatchRef.current(c, patch);
|
||||
}
|
||||
}),
|
||||
);
|
||||
unlisten.push(
|
||||
await listen("layer-settings-window-ready", () => {
|
||||
void emitTo(
|
||||
LAYER_SETTINGS_WINDOW_LABEL,
|
||||
"layer-settings-sync-state",
|
||||
stateRef.current,
|
||||
).catch(() => {});
|
||||
}),
|
||||
);
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
unlisten.forEach((u) => u());
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
void (async () => {
|
||||
const { emitTo } = await import("@tauri-apps/api/event");
|
||||
await emitTo(
|
||||
LAYER_SETTINGS_WINDOW_LABEL,
|
||||
"layer-settings-sync-state",
|
||||
stateRef.current,
|
||||
).catch(() => {});
|
||||
})();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- stateRef.current ist bereits die aktuelle Ableitung
|
||||
}, [project, code]);
|
||||
const state: LayerSettingsSyncState | null = code ? stateFor(project, code) : null;
|
||||
useWindowBridgeHost(LAYER_SETTINGS_WINDOW_LABEL, "layer-settings", state, { onPatchCategory: (c: string, patch: Partial<LayerCategory>) => onPatchCategory(c, patch) }, [project, code]);
|
||||
}
|
||||
@@ -13,11 +13,10 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { AiAccessView } from "../ui/AiAccessSection";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { isTauriRuntime } from "./projectFile";
|
||||
import type { LayoutState } from "../panels/types";
|
||||
import type { ThemeMode } from "../theme/themeMode";
|
||||
import { BORDERLESS_WINDOW_CHROME } from "./windowChrome";
|
||||
import { useWindowBridgeHost, type WindowHandlers } from "./windowBridge";
|
||||
|
||||
const SETTINGS_WINDOW_LABEL = "settings";
|
||||
|
||||
@@ -74,43 +73,5 @@ export function useSettingsWindowHost(
|
||||
state: SettingsSyncState,
|
||||
handlers: SettingsCommandHandlers,
|
||||
): void {
|
||||
const handlersRef = useRef(handlers);
|
||||
handlersRef.current = handlers;
|
||||
const stateRef = useRef(state);
|
||||
stateRef.current = state;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
let disposed = false;
|
||||
const unlisten: Array<() => void> = [];
|
||||
void (async () => {
|
||||
const { listen, emitTo } = await import("@tauri-apps/api/event");
|
||||
if (disposed) return;
|
||||
unlisten.push(
|
||||
await listen<{ name: string; args: unknown[] }>("settings-command", (e) => {
|
||||
const fn = (handlersRef.current as unknown as Record<string, unknown>)[e.payload.name];
|
||||
if (typeof fn === "function") (fn as (...a: unknown[]) => void)(...e.payload.args);
|
||||
}),
|
||||
);
|
||||
unlisten.push(
|
||||
await listen("settings-window-ready", () => {
|
||||
void emitTo(SETTINGS_WINDOW_LABEL, "settings-sync-state", stateRef.current).catch(
|
||||
() => {},
|
||||
);
|
||||
}),
|
||||
);
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
unlisten.forEach((u) => u());
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
void (async () => {
|
||||
const { emitTo } = await import("@tauri-apps/api/event");
|
||||
await emitTo(SETTINGS_WINDOW_LABEL, "settings-sync-state", state).catch(() => {});
|
||||
})();
|
||||
}, [state]);
|
||||
useWindowBridgeHost(SETTINGS_WINDOW_LABEL, "settings", state, handlers as unknown as WindowHandlers);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Gemeinsame Hauptfenster-Seite der Sync-Brücke zu den macOS-Nebenfenstern ([130]; vorher je Fenster kopiert).
|
||||
//
|
||||
// Hauptfenster → Nebenfenster: „<prefix>-sync-state" mit dem Zustand bei jeder Änderung und auf
|
||||
// „<prefix>-window-ready" (das Nebenfenster ist geladen und fragt nach).
|
||||
// Nebenfenster → Hauptfenster: „<prefix>-command" mit { name, args } — `name` ist ein Schlüssel von `handlers`.
|
||||
//
|
||||
// No-op ausserhalb von Tauri. Das Ressourcen-Fenster (resourceWindow.ts) schickt Teil-Änderungen und bleibt eigen.
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { isTauriRuntime } from "./projectFile";
|
||||
|
||||
/** Befehle eines Nebenfensters: Name → Funktion (Argumente kommen unverändert aus dem Fenster). */
|
||||
export type WindowHandlers = { [name: string]: (...args: never[]) => void };
|
||||
|
||||
/**
|
||||
* Hält das Nebenfenster `label` (falls offen) synchron zu `state` und wendet dessen Befehle auf `handlers` an.
|
||||
* `state` wird bei jeder neuen Identität gesendet; wer ihn bei jedem Render neu ableitet, übergibt `deps`.
|
||||
*/
|
||||
export function useWindowBridgeHost<S>(label: string, prefix: string, state: S, handlers: WindowHandlers, deps?: readonly unknown[]): void {
|
||||
const handlersRef = useRef(handlers);
|
||||
handlersRef.current = handlers;
|
||||
const stateRef = useRef(state);
|
||||
stateRef.current = state;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
let disposed = false;
|
||||
const unlisten: Array<() => void> = [];
|
||||
void (async () => {
|
||||
const { listen, emitTo } = await import("@tauri-apps/api/event");
|
||||
if (disposed) return;
|
||||
const offCommand = await listen<{ name: string; args: unknown[] }>(`${prefix}-command`, (e) => {
|
||||
const fn = handlersRef.current[e.payload.name] as ((...a: unknown[]) => void) | undefined;
|
||||
if (typeof fn === "function") fn(...(e.payload.args ?? []));
|
||||
});
|
||||
const offReady = await listen(`${prefix}-window-ready`, () => {
|
||||
void emitTo(label, `${prefix}-sync-state`, stateRef.current).catch(() => {});
|
||||
});
|
||||
if (disposed) {
|
||||
offCommand();
|
||||
offReady();
|
||||
return;
|
||||
}
|
||||
unlisten.push(offCommand, offReady);
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
unlisten.forEach((u) => u());
|
||||
};
|
||||
}, [label, prefix]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauriRuntime()) return;
|
||||
void (async () => {
|
||||
const { emitTo } = await import("@tauri-apps/api/event");
|
||||
await emitTo(label, `${prefix}-sync-state`, stateRef.current).catch(() => {});
|
||||
})();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- `deps` ersetzt `state`, wenn der Zustand je Render neu entsteht
|
||||
}, deps ?? [state]);
|
||||
}
|
||||
Reference in new issue
Block a user