Archived
nativeSync: nur pushen, wenn der Build ein natives Fenster hat
In der Tauri-App lief bei JEDER Planänderung (200 ms debounced) planToRenderScene über alle Primitive, die Szene wurde serialisiert und per IPC an push_native_scene geschickt — einen Befehl, den es im Standard-Build (ohne Feature native2d/native3d) gar nicht gibt; der Fehler wurde still geschluckt. Bei einem Kataster-Import (3,7 Mio. Primitive, bei gedimmten Referenz-Ebenen zusätzlich Klone) mehrere Sekunden reine Hauptthread-Last nach jeder Änderung, z. B. nach dem Zuweisen einer Schraffur. Neuer Befehl native_viewport_enabled (cfg!(native2d|native3d)); nativeSync fragt einmal und tut sonst nichts. Fehlt der Befehl (älterer Build), gilt das ebenfalls als "kein natives Fenster".
This commit is contained in:
1 parent
98bfea8a9a
commit
4c9d6a9d3f
2 files changed
+40
-2
No files matched your search
+28
-2
@@ -23,6 +23,30 @@ function isTauri(): boolean {
|
||||
return typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt es in diesem Build überhaupt ein natives Fenster (Rust-Features
|
||||
* native2d/native3d)? Einmal beim ersten Push erfragt. Ohne diese Prüfung
|
||||
* wurde bei JEDER Planänderung die komplette Szene in JS umgewandelt und per
|
||||
* IPC an einen Befehl geschickt, den es im Standard-Build nicht gibt —
|
||||
* bei einem Kataster-Import (3,7 Mio. Primitive) mehrere Sekunden
|
||||
* Hauptthread-Arbeit, nur um dann zu scheitern. Fehlt der Befehl selbst
|
||||
* (älterer Build), gilt das ebenfalls als "nein".
|
||||
*/
|
||||
let nativeEnabled: Promise<boolean> | null = null;
|
||||
function isNativeEnabled(): Promise<boolean> {
|
||||
nativeEnabled ??= (async () => {
|
||||
try {
|
||||
// @ts-ignore optionales Paket
|
||||
const mod = await import(/* @vite-ignore */ "@tauri-apps/api/core").catch(() => null);
|
||||
if (!mod || typeof (mod as any).invoke !== "function") return false;
|
||||
return (await (mod as any).invoke("native_viewport_enabled")) === true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
return nativeEnabled;
|
||||
}
|
||||
|
||||
/** Geguardeter Invoke (Muster wie src/compute): nie werfen, Fehler nur debuggen. */
|
||||
async function invokeNative(cmd: string, args: Record<string, unknown>): Promise<void> {
|
||||
try {
|
||||
@@ -45,7 +69,8 @@ let wallsTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
export function pushNativeScene(plan: Plan): void {
|
||||
if (!isTauri()) return;
|
||||
clearTimeout(sceneTimer);
|
||||
sceneTimer = setTimeout(() => {
|
||||
sceneTimer = setTimeout(async () => {
|
||||
if (!(await isNativeEnabled())) return;
|
||||
// planToRenderScene liest `greyed` am Primitiv → gedimmte Referenz-Ebenen materialisieren.
|
||||
void invokeNative("push_native_scene", { scene: planToRenderScene(materializeGreyed(plan, true)) });
|
||||
}, DEBOUNCE_MS);
|
||||
@@ -60,7 +85,8 @@ export function pushNativeWalls(project: Project): void {
|
||||
if (!isTauri()) return;
|
||||
lastProject = project;
|
||||
clearTimeout(wallsTimer);
|
||||
wallsTimer = setTimeout(() => {
|
||||
wallsTimer = setTimeout(async () => {
|
||||
if (!(await isNativeEnabled())) return;
|
||||
void invokeNative("push_native_walls", { walls: projectToModel3d(project) });
|
||||
}, DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user