cad-editor/src/main.rs
Hakan Seven 7f10b69e3c feat(automation): headless JSON server (--serve) + Python client
Add an external automation API (issue #29 / #100 track 2): `OpenCADStudio
--serve` runs without a GUI and is driven over a line-based JSON protocol
on stdin/stdout — open / new / run / entities / save. State persists
across requests so a script or AI agent can act, observe, and act again.

`run` drives the app's existing command system rather than a separate
binding, so coverage grows with the app; synchronous commands apply now,
pick-based interactive ones come once coordinate feeding is wired. Ships
a ~100-line example ocs.py client over the same protocol — no FFI to
maintain. Headless works because the app already constructs and dispatches
GUI-less in tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 21:05:12 +03:00

51 lines
1.6 KiB
Rust

#![allow(non_snake_case)]
// On Windows release builds, hide the console window the OS would
// otherwise spawn alongside the GUI. Debug builds keep stdout/stderr
// attached so eprintln! / panics stay visible while developing.
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
mod app;
mod command;
mod entities;
mod io;
mod linetypes;
mod modules;
mod plugin;
mod patterns;
mod scene;
mod snap;
mod ui;
mod par;
mod sys;
mod update_check;
fn main() -> iced::Result {
// On some Windows hybrid-GPU laptops the AMD OpenGL driver (atio6axx.dll)
// access-violates the moment wgpu enumerates its GL backend at startup,
// killing the app before any window appears — even though DX12 would work
// fine (#55). Restrict wgpu to DX12/Vulkan so the GL ICD is never touched.
// An explicit user-set WGPU_BACKEND still wins.
#[cfg(target_os = "windows")]
if std::env::var_os("WGPU_BACKEND").is_none() {
std::env::set_var("WGPU_BACKEND", "dx12,vulkan");
}
// Web (wasm) uses the single-window entry; native uses the multi-window
// daemon. Trunk calls `main` from its generated JS bootstrap.
#[cfg(target_arch = "wasm32")]
{
console_error_panic_hook::set_once();
app::run_web()
}
#[cfg(not(target_arch = "wasm32"))]
{
// Headless automation server — drive the app over JSON on stdin/stdout
// with no GUI (issue #29). `--serve` is the opt-in; everything else
// launches the editor.
if std::env::args().skip(1).any(|a| a == "--serve") {
app::serve();
return Ok(());
}
app::run()
}
}