Răsfoiți Sursa

added some logging to ckeck shii

xdw 3 luni în urmă
părinte
comite
20bf53658b
1 a modificat fișierele cu 40 adăugiri și 12 ștergeri
  1. 40 12
      server/index.ts

+ 40 - 12
server/index.ts

@@ -138,7 +138,6 @@ const WindowsDriver: Driver = {
 // method that works with both windowed and fullscreen slideshow modes).
 // method that works with both windowed and fullscreen slideshow modes).
 
 
 function pyUno(script: string): Promise<string> {
 function pyUno(script: string): Promise<string> {
-  // Inline python passed via -c; single-quotes escaped for shell
   return run("python3", ["-c", script]);
   return run("python3", ["-c", script]);
 }
 }
 
 
@@ -179,6 +178,7 @@ const LinuxDriver: Driver = {
   },
   },
 
 
   async status() {
   async status() {
+    console.log("[linux] status: running UNO query");
     const raw = await pyUno(`
     const raw = await pyUno(`
 import sys
 import sys
 try:
 try:
@@ -197,18 +197,22 @@ try:
     try:
     try:
         controller = comp.getCurrentController()
         controller = comp.getCurrentController()
         current = controller.getCurrentPage().PageIndex + 1
         current = controller.getCurrentPage().PageIndex + 1
-    except:
+    except Exception as inner:
+        print(f"[status] could not get current page: {inner}", file=sys.stderr)
         current = 0
         current = 0
     print(f"{current}/{total}")
     print(f"{current}/{total}")
 except Exception as e:
 except Exception as e:
-    print(f"0/0", file=sys.stderr)
+    print(f"[status] UNO error: {e}", file=sys.stderr)
     print("0/0")
     print("0/0")
 `);
 `);
-    return parseSlide(raw);
+    console.log(`[linux] status raw output: "${raw}"`);
+    const result = parseSlide(raw);
+    console.log(`[linux] status parsed: current=${result.current} total=${result.total}`);
+    return result;
   },
   },
 
 
   async slideImage(index: number) {
   async slideImage(index: number) {
-    // Export the slide via UNO as PNG, return base64
+    console.log(`[linux] slideImage: exporting slide index=${index}`);
     const raw = await pyUno(`
     const raw = await pyUno(`
 import sys, os, base64, tempfile
 import sys, os, base64, tempfile
 try:
 try:
@@ -223,8 +227,11 @@ try:
     desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
     desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
     comp = desktop.getCurrentComponent()
     comp = desktop.getCurrentComponent()
     draw = comp.DrawPages
     draw = comp.DrawPages
+    print(f"[slideImage] total slides: {draw.Count}", file=sys.stderr)
     slide = draw.getByIndex(${index - 1})
     slide = draw.getByIndex(${index - 1})
+    print(f"[slideImage] got slide object: {slide}", file=sys.stderr)
     tmp = tempfile.mktemp(suffix='.png')
     tmp = tempfile.mktemp(suffix='.png')
+    print(f"[slideImage] exporting to: {tmp}", file=sys.stderr)
     graphicExporter = smgr.createInstanceWithContext(
     graphicExporter = smgr.createInstanceWithContext(
         "com.sun.star.drawing.GraphicExportFilter", ctx)
         "com.sun.star.drawing.GraphicExportFilter", ctx)
     graphicExporter.setSourceDocument(slide)
     graphicExporter.setSourceDocument(slide)
@@ -238,14 +245,27 @@ try:
     props.append(mkprop("MediaType", "image/png"))
     props.append(mkprop("MediaType", "image/png"))
     props.append(mkprop("Selection", slide))
     props.append(mkprop("Selection", slide))
     graphicExporter.filter(tuple(props))
     graphicExporter.filter(tuple(props))
-    with open(tmp, 'rb') as f:
-        print(base64.b64encode(f.read()).decode())
-    os.unlink(tmp)
+    if os.path.exists(tmp):
+        size = os.path.getsize(tmp)
+        print(f"[slideImage] exported file size: {size} bytes", file=sys.stderr)
+        with open(tmp, 'rb') as f:
+            data = f.read()
+        b64 = base64.b64encode(data).decode()
+        print(f"[slideImage] base64 length: {len(b64)}", file=sys.stderr)
+        print(b64)
+        os.unlink(tmp)
+    else:
+        print(f"[slideImage] export file not created at {tmp}", file=sys.stderr)
+        print("")
 except Exception as e:
 except Exception as e:
-    print("", file=sys.stdout)
-    print(str(e), file=sys.stderr)
+    import traceback
+    print(f"[slideImage] exception: {e}", file=sys.stderr)
+    traceback.print_exc(file=sys.stderr)
+    print("")
 `);
 `);
-    return raw;
+    const trimmed = raw.trim();
+    console.log(`[linux] slideImage: got output length=${trimmed.length}${trimmed.length === 0 ? " (EMPTY — check stderr above)" : ""}`);
+    return trimmed;
   },
   },
 };
 };
 
 
@@ -515,12 +535,20 @@ async function handleCmd(cmd: string): Promise<void> {
     return;
     return;
   }
   }
 
 
+  console.log(`[cmd] executing: ${cmd}`);
   const { current, total } = await driver[cmd as NavCmd]();
   const { current, total } = await driver[cmd as NavCmd]();
+  console.log(`[cmd] result: current=${current} total=${total}`);
   broadcast({ event: "slide", current, total });
   broadcast({ event: "slide", current, total });
 
 
   if (current > 0 && cmd !== "end") {
   if (current > 0 && cmd !== "end") {
+    console.log(`[cmd] requesting slide image for index=${current}`);
     const b64 = await driver.slideImage(current);
     const b64 = await driver.slideImage(current);
-    if (b64) broadcast({ event: "image", data: b64 });
+    if (b64) {
+      console.log(`[cmd] broadcasting image, base64 length=${b64.length}`);
+      broadcast({ event: "image", data: b64 });
+    } else {
+      console.warn(`[cmd] slideImage returned empty for index=${current}`);
+    }
   }
   }
 }
 }